mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
Fixed prefab serialization and instancing into scene
This commit is contained in:
@@ -85,25 +85,21 @@ namespace Nuake
|
||||
Entity newEntity = { entity.GetScene()->m_Registry.create(), entity.GetScene() };
|
||||
newEntity.Deserialize(e); // Id gets overriden by serialized id.
|
||||
|
||||
if (newEntity.GetComponent<ParentComponent>().HasParent)
|
||||
ParentComponent& parentComponent = newEntity.GetComponent<ParentComponent>();
|
||||
if (parentComponent.HasParent && parentComponent.ParentID != j["Root"])
|
||||
{
|
||||
auto pId = newEntity.GetComponent<ParentComponent>().ParentID;
|
||||
newEntity.GetComponent<ParentComponent>().ParentID = newIdsLut[pId];
|
||||
auto nc = entity.GetScene()->GetEntityByID(pId);
|
||||
nc.GetComponent<ParentComponent>().RemoveChildren(newEntity);
|
||||
newEntity.GetComponent<ParentComponent>().Parent = entity.GetScene()->GetEntityByID(newIdsLut[pId]);
|
||||
entity.GetScene()->GetEntityByID(newIdsLut[pId]).AddChild(newEntity);
|
||||
|
||||
|
||||
//auto pId = newEntity.GetComponent<ParentComponent>().ParentID;
|
||||
//newEntity.GetComponent<ParentComponent>().ParentID = newIdsLut[pId];
|
||||
//auto nc = entity.GetScene()->GetEntityByID(pId).GetComponent<ParentComponent>().RemoveChildren(newEntity);
|
||||
//newEntity.GetComponent<ParentComponent>().Parent = entity.GetScene()->GetEntityByID(newIdsLut[pId]);
|
||||
//entity.GetScene()->GetEntityByID(newIdsLut[pId]).AddChild(newEntity);
|
||||
}
|
||||
|
||||
if (newEntity.GetComponent<ParentComponent>().ParentID == j["Root"])
|
||||
else if (newEntity.GetComponent<ParentComponent>().ParentID == j["Root"])
|
||||
{
|
||||
entity.AddChild(newEntity);
|
||||
//entity.AddChild(newEntity);
|
||||
}
|
||||
|
||||
auto& nameComponent = newEntity.GetComponent<NameComponent>();
|
||||
|
||||
uint32_t oldId = nameComponent.ID;
|
||||
uint32_t newId = OS::GetTime();
|
||||
nameComponent.Name = nameComponent.Name;
|
||||
@@ -117,18 +113,18 @@ namespace Nuake
|
||||
// Set reference to the parent entity to children
|
||||
for (auto& e : newPrefab->Entities)
|
||||
{
|
||||
auto& parentC = e.GetComponent<ParentComponent>();
|
||||
auto parent = entity.GetScene()->GetEntityByID(newIdsLut[parentC.ParentID]);
|
||||
|
||||
Logger::Log(parent.GetComponent<NameComponent>().Name);
|
||||
if (parentC.ParentID == j["Root"])
|
||||
{
|
||||
entity.AddChild(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.AddChild(e);
|
||||
}
|
||||
//auto& parentC = e.GetComponent<ParentComponent>();
|
||||
//auto parent = entity.GetScene()->GetEntityByID(newIdsLut[parentC.ParentID]);
|
||||
//
|
||||
//Logger::Log(parent.GetComponent<NameComponent>().Name);
|
||||
//if (parentC.ParentID == j["Root"])
|
||||
//{
|
||||
// entity.AddChild(e);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// parent.AddChild(e);
|
||||
//}
|
||||
}
|
||||
|
||||
// Since the bones point to an entity, and we are instancing a prefab, the new skeleton is gonna be pointing to the wrong
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace Nuake {
|
||||
Ref<Prefab> PrefabInstance;
|
||||
std::string Path;
|
||||
|
||||
bool isInitialized = false;
|
||||
|
||||
void SetPrefab(Ref<Prefab> prefab)
|
||||
{
|
||||
PrefabInstance = prefab;
|
||||
|
||||
@@ -136,8 +136,9 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
Prefab::InstanceOntoRoot(Entity{(entt::entity)GetHandle(), m_Scene}, prefabPath);
|
||||
|
||||
prefabComp.PrefabInstance = Prefab::InstanceOntoRoot(Entity{(entt::entity)GetHandle(), m_Scene}, prefabPath);
|
||||
prefabComp.Path = prefabPath;
|
||||
|
||||
DeserializeComponents(rootJson);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -318,7 +318,7 @@ namespace Nuake
|
||||
}
|
||||
|
||||
Ref<File> file = FileSystem::GetFile(filePath);
|
||||
if (file->GetHasBeenModified())
|
||||
if (file->GetHasBeenModified() || !prefabComponent.isInitialized)
|
||||
{
|
||||
prefabToReimport[filePath] = file;
|
||||
}
|
||||
@@ -342,7 +342,6 @@ namespace Nuake
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (auto& ent : prefabInstance->Entities)
|
||||
{
|
||||
// Destroy all children, not the root!
|
||||
@@ -358,6 +357,7 @@ namespace Nuake
|
||||
});
|
||||
|
||||
prefabInstance->ReInstance();
|
||||
prefabComponent.isInitialized = true;
|
||||
}
|
||||
|
||||
for (auto& [path, prefabFile] : prefabToReimport)
|
||||
|
||||
Reference in New Issue
Block a user