54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <ryml_std.hpp>
|
|
|
|
#include "asset_base.hpp"
|
|
#include "transform.hpp"
|
|
|
|
struct GameObjectAsset : public AssetBase
|
|
{
|
|
std::string name;
|
|
uint8_t layer{ 0 };
|
|
uint8_t namMeshLayer{ 0 };
|
|
std::string tag;
|
|
|
|
TransformAsset* transform{ nullptr };
|
|
std::vector<AssetBase*> Components;
|
|
};
|
|
|
|
inline GameObjectAsset ParseGameObject(const ryml::ConstNodeRef& node)
|
|
{
|
|
GameObjectAsset gameObject;
|
|
|
|
node["m_Name"] >> gameObject.name;
|
|
node["m_Layer"] >> gameObject.layer;
|
|
node["m_TagString"] >> gameObject.tag;
|
|
|
|
auto components = node["m_Component"];
|
|
auto it = components.begin();
|
|
|
|
gameObject.transform = ParseAssetRef<TransformAsset>((*it)["component"]);
|
|
++it;
|
|
for (; it != components.end(); ++it)
|
|
{
|
|
gameObject.Components.push_back(ParseAssetRef<AssetBase>((*it)["component"]));
|
|
}
|
|
|
|
return gameObject;
|
|
}
|
|
|
|
inline void LinkGameObject(const std::unordered_map<int64_t, AssetBase*>& assetsMap, GameObjectAsset& gameObject)
|
|
{
|
|
LinkAssetRef<TransformAsset>(assetsMap, gameObject.transform);
|
|
for (int i = static_cast<int>(gameObject.Components.size()) - 1; i >= 0; i--)
|
|
{
|
|
if (!LinkAssetRef<AssetBase>(assetsMap, gameObject.Components[i]))
|
|
{
|
|
std::swap(gameObject.Components[i], gameObject.Components.back());
|
|
gameObject.Components.pop_back();
|
|
}
|
|
}
|
|
} |