feat(new_editor): add standalone add-component utility window

This commit is contained in:
2026-04-22 22:07:02 +08:00
parent 865a35e4d0
commit 3048c7cc90
37 changed files with 1237 additions and 290 deletions

View File

@@ -1,5 +1,6 @@
#include "Scene/EditorSceneRuntime.h"
#include <XCEngine/Components/ComponentFactoryRegistry.h>
#include <XCEngine/Components/CameraComponent.h>
#include <XCEngine/Components/Component.h>
#include <XCEngine/Components/GameObject.h>
@@ -472,6 +473,36 @@ bool EditorSceneRuntime::MoveGameObjectToRoot(std::string_view itemId) {
return moved;
}
bool EditorSceneRuntime::AddComponentToSelectedGameObject(
std::string_view componentTypeName) {
if (componentTypeName.empty()) {
return false;
}
const std::optional<GameObject::ID> selectedId = GetSelectedGameObjectId();
Scene* scene = GetActiveScene();
if (!selectedId.has_value() || scene == nullptr) {
return false;
}
GameObject* gameObject = scene->FindByID(selectedId.value());
if (gameObject == nullptr) {
return false;
}
Component* addedComponent =
::XCEngine::Components::ComponentFactoryRegistry::Get().CreateComponent(
gameObject,
std::string(componentTypeName));
if (addedComponent == nullptr) {
return false;
}
IncrementInspectorRevision();
RefreshScene();
return true;
}
bool EditorSceneRuntime::CanRemoveSelectedComponent(
std::string_view componentId) const {
const EditorSceneComponentDescriptor descriptor =