From b27438c3e33ec06f89285f057b72a23baa7929a2 Mon Sep 17 00:00:00 2001 From: antopilo Date: Thu, 26 Aug 2021 23:45:43 -0400 Subject: [PATCH] prefab component --- Editor/src/EditorInterface.cpp | 20 +++++++++++--------- Nuake/src/Scene/Components/PrefabComponent.h | 11 +++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 Nuake/src/Scene/Components/PrefabComponent.h diff --git a/Editor/src/EditorInterface.cpp b/Editor/src/EditorInterface.cpp index 5aad17ee..207520b9 100644 --- a/Editor/src/EditorInterface.cpp +++ b/Editor/src/EditorInterface.cpp @@ -30,6 +30,7 @@ #include "src/Scene/Components/LightComponent.h" #include "UIComponents/Viewport.h" #include +#include namespace Nuake { Ref userInterface; @@ -174,18 +175,18 @@ namespace Nuake { if (parent.Children.size() <= 0) base_flags |= ImGuiTreeNodeFlags_Leaf; - if(nameComponent.IsPrefab) + if(nameComponent.IsPrefab && e.HasComponent()) ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0,255,0,255)); bool open = ImGui::TreeNodeEx(name.c_str(), base_flags); - if(nameComponent.IsPrefab) + if(nameComponent.IsPrefab && e.HasComponent()) ImGui::PopStyleColor(); - - if (ImGui::BeginDragDropSource()) - { - ImGui::SetDragDropPayload("ENTITY", (void*)&e, sizeof(Entity)); - ImGui::Text(name.c_str()); - ImGui::EndDragDropSource(); - } + else + if (ImGui::BeginDragDropSource()) + { + ImGui::SetDragDropPayload("ENTITY", (void*)&e, sizeof(Entity)); + ImGui::Text(name.c_str()); + ImGui::EndDragDropSource(); + } if (ImGui::BeginDragDropTarget()) { @@ -240,6 +241,7 @@ namespace Nuake { Ref newPrefab = Prefab::CreatePrefabFromEntity(m_SelectedEntity); std::string savePath = FileDialog::SaveFile("*.prefab"); newPrefab->SaveAs(savePath); + m_SelectedEntity.AddComponent().PrefabInstance = newPrefab; } ImGui::EndPopup(); } diff --git a/Nuake/src/Scene/Components/PrefabComponent.h b/Nuake/src/Scene/Components/PrefabComponent.h new file mode 100644 index 00000000..9f717636 --- /dev/null +++ b/Nuake/src/Scene/Components/PrefabComponent.h @@ -0,0 +1,11 @@ +#pragma once +#include "src/Core/Core.h" +#include "src/Resource/Prefab.h" + +namespace Nuake { + class PrefabComponent + { + public: + Ref PrefabInstance; + }; +} \ No newline at end of file