Minor improvements with prefab deserialization

This commit is contained in:
antopilo
2024-09-19 21:36:44 -04:00
parent 6ac1ff8386
commit 3d9cda2990
2 changed files with 19 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ PrefabEditorWindow::PrefabEditorWindow(Ref<Prefab> inPrefab) :
virtualScene->GetEnvironment()->CurrentSkyType = SkyType::ProceduralSky;
virtualScene->GetEnvironment()->ProceduralSkybox->SunDirection = { 0.58f, 0.34f, -0.74f };
prefab = Prefab::InstanceInScene(inPrefab->Path, virtualScene);
prefab = Prefab::InstanceInScene(inPrefab->Path, virtualScene.get());
prefab->Path = inPrefab->Path;
Ref<Texture> outputTexture = CreateRef<Texture>(defaultSize, GL_RGB);

View File

@@ -85,6 +85,23 @@ 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)
{
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);
}
if (newEntity.GetComponent<ParentComponent>().ParentID == j["Root"])
{
entity.AddChild(newEntity);
}
auto& nameComponent = newEntity.GetComponent<NameComponent>();
uint32_t oldId = nameComponent.ID;
@@ -103,6 +120,7 @@ namespace Nuake
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);