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

@@ -0,0 +1,45 @@
#include "ComponentEditors/ComponentEditorRegistry.h"
#include "ComponentEditors/CameraComponentEditor.h"
#include "ComponentEditors/LightComponentEditor.h"
#include "ComponentEditors/TransformComponentEditor.h"
namespace XCEngine {
namespace Editor {
ComponentEditorRegistry& ComponentEditorRegistry::Get() {
static ComponentEditorRegistry registry;
return registry;
}
ComponentEditorRegistry::ComponentEditorRegistry() {
RegisterEditor(std::make_unique<TransformComponentEditor>());
RegisterEditor(std::make_unique<CameraComponentEditor>());
RegisterEditor(std::make_unique<LightComponentEditor>());
}
void ComponentEditorRegistry::RegisterEditor(std::unique_ptr<IComponentEditor> editor) {
if (!editor) {
return;
}
IComponentEditor* editorPtr = editor.get();
m_editorsByType[editor->GetComponentTypeName()] = editorPtr;
m_editors.push_back(std::move(editor));
}
IComponentEditor* ComponentEditorRegistry::FindEditor(::XCEngine::Components::Component* component) const {
return component ? FindEditorByTypeName(component->GetName()) : nullptr;
}
IComponentEditor* ComponentEditorRegistry::FindEditorByTypeName(const std::string& componentTypeName) const {
const auto it = m_editorsByType.find(componentTypeName);
return it != m_editorsByType.end() ? it->second : nullptr;
}
const std::vector<std::unique_ptr<IComponentEditor>>& ComponentEditorRegistry::GetEditors() const {
return m_editors;
}
} // namespace Editor
} // namespace XCEngine