feat(new_editor): add standalone add-component utility window
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user