Fix editor scene persistence and XC scene workflow

This commit is contained in:
2026-03-26 01:26:26 +08:00
parent 39edb0b497
commit 0651666d8c
35 changed files with 1958 additions and 256 deletions

View File

@@ -6,6 +6,8 @@
#include "Core/EventBus.h"
#include <XCEngine/Core/Math/Vector3.h>
#include <XCEngine/Core/Math/Quaternion.h>
#include <XCEngine/Components/CameraComponent.h>
#include <XCEngine/Components/LightComponent.h>
#include <imgui.h>
#include <cstring>
@@ -22,9 +24,6 @@ HierarchyPanel::~HierarchyPanel() {
}
void HierarchyPanel::OnAttach() {
auto& sceneManager = m_context->GetSceneManager();
sceneManager.CreateDemoScene();
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
[this](const SelectionChangedEvent& event) {
OnSelectionChanged(event);
@@ -74,7 +73,16 @@ void HierarchyPanel::Render() {
::XCEngine::Components::GameObject* sourceGameObject = *(::XCEngine::Components::GameObject**)payload->Data;
if (sourceGameObject && sourceGameObject->GetParent() != nullptr) {
auto& sceneManager = m_context->GetSceneManager();
auto* srcTransform = sourceGameObject->GetTransform();
Math::Vector3 worldPos = srcTransform->GetPosition();
Math::Quaternion worldRot = srcTransform->GetRotation();
Math::Vector3 worldScale = srcTransform->GetScale();
sceneManager.MoveEntity(sourceGameObject->GetID(), 0);
srcTransform->SetPosition(worldPos);
srcTransform->SetRotation(worldRot);
srcTransform->SetScale(worldScale);
}
}
ImGui::EndDragDropTarget();
@@ -195,7 +203,7 @@ void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* gameO
if (gameObject != nullptr && gameObject->GetParent() != nullptr) {
if (ImGui::MenuItem("Detach from Parent")) {
gameObject->DetachFromParent();
sceneManager.MoveEntity(gameObject->GetID(), 0);
}
}
@@ -242,12 +250,13 @@ void HierarchyPanel::RenderCreateMenu(::XCEngine::Components::GameObject* parent
if (ImGui::MenuItem("Camera")) {
auto* newEntity = sceneManager.CreateEntity("Camera", parent);
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
newEntity->AddComponent<::XCEngine::Components::CameraComponent>();
selectionManager.SetSelectedEntity(newEntity->GetID());
}
if (ImGui::MenuItem("Light")) {
auto* newEntity = sceneManager.CreateEntity("Light", parent);
newEntity->AddComponent<::XCEngine::Components::LightComponent>();
selectionManager.SetSelectedEntity(newEntity->GetID());
}
@@ -255,19 +264,16 @@ void HierarchyPanel::RenderCreateMenu(::XCEngine::Components::GameObject* parent
if (ImGui::MenuItem("Cube")) {
auto* newEntity = sceneManager.CreateEntity("Cube", parent);
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
selectionManager.SetSelectedEntity(newEntity->GetID());
}
if (ImGui::MenuItem("Sphere")) {
auto* newEntity = sceneManager.CreateEntity("Sphere", parent);
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
selectionManager.SetSelectedEntity(newEntity->GetID());
}
if (ImGui::MenuItem("Plane")) {
auto* newEntity = sceneManager.CreateEntity("Plane", parent);
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
selectionManager.SetSelectedEntity(newEntity->GetID());
}
}