refactor(editor): Complete architecture refactoring

- SceneManager: remove singleton, use dependency injection via EditorContext
- SelectionManager: already interface-based via ISelectionManager
- Panel: now receives IEditorContext for accessing managers
- HierarchyPanel: migrated to use IEditorContext instead of singletons
- Add ISceneManager interface and SceneManagerImpl
- EditorContextImpl: holds all editor subsystems

Architecture now follows dependency injection pattern:
Application -> EditorContext -> SceneManager/SelectionManager
EditorLayer -> Panels (receive context via SetContext)

All Manager singletons removed: EditorSceneManager::Get(), SelectionManager::Get()
This commit is contained in:
2026-03-25 15:51:27 +08:00
parent 56ec2e9b85
commit 008fb98dee
18 changed files with 1491 additions and 181 deletions

View File

@@ -4,6 +4,8 @@
#include <vector>
#include <memory>
#include <optional>
#include <string>
#include <cstdint>
#include <XCEngine/Core/Event.h>
#include <XCEngine/Core/Math/Vector3.h>
@@ -11,16 +13,17 @@
#include <XCEngine/Components/GameObject.h>
#include <XCEngine/Scene/Scene.h>
#include "Core/ISelectionManager.h"
namespace XCEngine {
namespace Editor {
class EditorSceneManager {
public:
static EditorSceneManager& Get() {
static EditorSceneManager instance;
return instance;
}
class ISelectionManager;
class SceneManager {
public:
SceneManager();
::XCEngine::Components::GameObject* CreateEntity(const std::string& name, ::XCEngine::Components::GameObject* parent = nullptr);
::XCEngine::Components::GameObject* GetEntity(::XCEngine::Components::GameObject::ID id) {
@@ -37,12 +40,7 @@ public:
void DeleteEntity(::XCEngine::Components::GameObject::ID id);
void RenameEntity(::XCEngine::Components::GameObject::ID id, const std::string& newName) {
if (auto* entity = GetEntity(id)) {
entity->SetName(newName);
OnEntityChanged.Invoke(id);
}
}
void RenameEntity(::XCEngine::Components::GameObject::ID id, const std::string& newName);
void CopyEntity(::XCEngine::Components::GameObject::ID id);
::XCEngine::Components::GameObject::ID PasteEntity(::XCEngine::Components::GameObject::ID parent = 0);
@@ -52,6 +50,8 @@ public:
void CreateDemoScene();
bool HasClipboardData() const { return m_clipboard.has_value(); }
void SetSelectionManager(ISelectionManager* selectionManager);
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityCreated;
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityDeleted;
@@ -59,8 +59,6 @@ public:
::XCEngine::Core::Event<> OnSceneChanged;
private:
EditorSceneManager() = default;
struct ClipboardData {
std::string name;
Math::Vector3 localPosition = Math::Vector3::Zero();
@@ -75,6 +73,7 @@ private:
::XCEngine::Components::Scene* m_scene = nullptr;
std::vector<::XCEngine::Components::GameObject*> m_rootEntities;
std::optional<ClipboardData> m_clipboard;
ISelectionManager* m_selectionManager = nullptr;
};
}