Refactor new editor scene runtime ownership

This commit is contained in:
2026-04-18 00:45:14 +08:00
parent 2fe1076218
commit b48760ca3d
12 changed files with 792 additions and 326 deletions

View File

@@ -1,5 +1,8 @@
#include "InspectorPanel.h"
#include "Scene/EditorSceneRuntime.h"
#include <XCEditor/App/EditorPanelIds.h>
#include <XCEditor/Foundation/UIEditorTheme.h>
#include <algorithm>
@@ -13,7 +16,6 @@ using ::XCEngine::UI::UIDrawList;
using ::XCEngine::UI::UIPoint;
using ::XCEngine::UI::UIRect;
constexpr std::string_view kInspectorPanelId = "inspector";
constexpr float kPanelPadding = 10.0f;
constexpr float kHeaderHeight = 22.0f;
constexpr float kSectionGap = 10.0f;
@@ -55,32 +57,15 @@ const UIEditorPanelContentHostPanelState* InspectorPanel::FindMountedInspectorPa
return nullptr;
}
void InspectorPanel::BuildPresentation(const EditorSession& session) {
void InspectorPanel::BuildPresentation(
const EditorSession& session,
const EditorSceneRuntime& sceneRuntime) {
m_sections.clear();
m_title.clear();
m_subtitle.clear();
m_hasSelection = false;
switch (session.selection.kind) {
case EditorSelectionKind::HierarchyNode: {
m_hasSelection = true;
m_title = session.selection.displayName.empty()
? std::string("GameObject")
: session.selection.displayName;
m_subtitle = "GameObject";
Section identity = {};
identity.title = "Identity";
identity.rows = {
{ "Type", "GameObject" },
{ "Name", m_title },
{ "Id", session.selection.itemId }
};
m_sections.push_back(std::move(identity));
break;
}
case EditorSelectionKind::ProjectItem: {
if (session.selection.kind == EditorSelectionKind::ProjectItem) {
m_hasSelection = true;
m_title = session.selection.displayName.empty()
? (session.selection.directory ? std::string("Folder") : std::string("Asset"))
@@ -102,19 +87,50 @@ void InspectorPanel::BuildPresentation(const EditorSession& session) {
{ "Path", PathToUtf8String(session.selection.absolutePath) }
};
m_sections.push_back(std::move(location));
break;
return;
}
case EditorSelectionKind::None:
default:
m_title = "Nothing selected";
m_subtitle = "Select a hierarchy item or project asset.";
break;
if (session.selection.kind == EditorSelectionKind::HierarchyNode &&
sceneRuntime.HasSceneSelection()) {
const auto* selectedGameObject = sceneRuntime.GetSelectedGameObject();
m_hasSelection = true;
m_title = sceneRuntime.GetSelectedDisplayName().empty()
? std::string("GameObject")
: sceneRuntime.GetSelectedDisplayName();
m_subtitle = "GameObject";
Section identity = {};
identity.title = "Identity";
identity.rows = {
{ "Type", "GameObject" },
{ "Name", m_title },
{ "Id", sceneRuntime.GetSelectedItemId() }
};
m_sections.push_back(std::move(identity));
if (selectedGameObject != nullptr) {
Section hierarchy = {};
hierarchy.title = "Hierarchy";
hierarchy.rows = {
{ "Children", std::to_string(selectedGameObject->GetChildCount()) },
{ "Parent", selectedGameObject->GetParent() != nullptr
? (selectedGameObject->GetParent()->GetName().empty()
? std::string("GameObject")
: selectedGameObject->GetParent()->GetName())
: std::string("Scene Root") }
};
m_sections.push_back(std::move(hierarchy));
}
return;
}
m_title = "Nothing selected";
m_subtitle = "Select a hierarchy item or project asset.";
}
void InspectorPanel::Update(
const EditorSession& session,
const EditorSceneRuntime& sceneRuntime,
const UIEditorPanelContentHostFrame& contentHostFrame) {
const UIEditorPanelContentHostPanelState* panelState =
FindMountedInspectorPanel(contentHostFrame);
@@ -130,7 +146,7 @@ void InspectorPanel::Update(
m_visible = true;
m_bounds = panelState->bounds;
BuildPresentation(session);
BuildPresentation(session, sceneRuntime);
}
void InspectorPanel::Append(UIDrawList& drawList) const {