feat(editor): unify component registration pipeline

This commit is contained in:
2026-03-26 02:24:11 +08:00
parent 1ef3048da1
commit d018a4c82c
17 changed files with 268 additions and 116 deletions

View File

@@ -5,10 +5,8 @@
#include "Core/IUndoManager.h"
#include "Core/EventBus.h"
#include "Core/EditorEvents.h"
#include "ComponentEditors/CameraComponentEditor.h"
#include "ComponentEditors/ComponentEditorRegistry.h"
#include "ComponentEditors/IComponentEditor.h"
#include "ComponentEditors/LightComponentEditor.h"
#include "ComponentEditors/TransformComponentEditor.h"
#include "Utils/UndoUtils.h"
#include <imgui.h>
#include <string>
@@ -16,9 +14,7 @@
namespace XCEngine {
namespace Editor {
InspectorPanel::InspectorPanel() : Panel("Inspector") {
RegisterDefaultComponentEditors();
}
InspectorPanel::InspectorPanel() : Panel("Inspector") {}
InspectorPanel::~InspectorPanel() {
if (m_context) {
@@ -33,34 +29,6 @@ void InspectorPanel::OnSelectionChanged(const SelectionChangedEvent& event) {
m_selectedEntityId = event.primarySelection;
}
void InspectorPanel::RegisterDefaultComponentEditors() {
RegisterComponentEditor(std::make_unique<TransformComponentEditor>());
RegisterComponentEditor(std::make_unique<CameraComponentEditor>());
RegisterComponentEditor(std::make_unique<LightComponentEditor>());
}
void InspectorPanel::RegisterComponentEditor(std::unique_ptr<IComponentEditor> editor) {
if (!editor) {
return;
}
m_componentEditors.push_back(std::move(editor));
}
IComponentEditor* InspectorPanel::GetEditorFor(::XCEngine::Components::Component* component) const {
if (!component) {
return nullptr;
}
for (const auto& editor : m_componentEditors) {
if (editor && editor->CanEdit(component)) {
return editor.get();
}
}
return nullptr;
}
void InspectorPanel::Render() {
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
@@ -126,7 +94,7 @@ void InspectorPanel::RenderAddComponentPopup(::XCEngine::Components::GameObject*
ImGui::Separator();
bool drewAnyEntry = false;
for (const auto& editor : m_componentEditors) {
for (const auto& editor : ComponentEditorRegistry::Get().GetEditors()) {
if (!editor || !editor->ShowInAddComponentMenu()) {
continue;
}
@@ -167,7 +135,7 @@ void InspectorPanel::RenderAddComponentPopup(::XCEngine::Components::GameObject*
void InspectorPanel::RenderComponent(::XCEngine::Components::Component* component, ::XCEngine::Components::GameObject* gameObject) {
if (!component) return;
IComponentEditor* editor = GetEditorFor(component);
IComponentEditor* editor = ComponentEditorRegistry::Get().FindEditor(component);
const char* name = component->GetName().c_str();