Files
XCEngine/ui/src/panels/InspectorPanel.cpp
ssdfasd a2f3db8718 重构UI架构:分离数据模型和显示逻辑
- 新增 Core 模块:GameObject、LogEntry、AssetItem 数据模型
- 新增 Managers 模块:SceneManager、LogSystem、ProjectManager
- Panel 层只负责显示,不再持有数据
- 解耦 HierarchyPanel 和 InspectorPanel 之间的直接依赖
2026-03-12 16:13:34 +08:00

78 lines
2.4 KiB
C++

#include "InspectorPanel.h"
#include "Managers/SceneManager.h"
#include "Core/GameObject.h"
#include <imgui.h>
namespace UI {
InspectorPanel::InspectorPanel() : Panel("Inspector") {}
void InspectorPanel::Render() {
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
GameObject* selected = SceneManager::Get().GetSelectedObject();
if (selected) {
ImGui::Text("%s", selected->name.c_str());
ImGui::Separator();
auto transform = selected->GetComponent<TransformComponent>();
if (transform) {
RenderTransformSection(transform);
ImGui::Separator();
}
auto meshRenderer = selected->GetComponent<MeshRendererComponent>();
if (meshRenderer) {
RenderMeshRendererSection(meshRenderer);
}
} else {
ImGui::Text("No object selected");
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
}
ImGui::End();
}
void InspectorPanel::RenderTransformSection(TransformComponent* transform) {
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent(10.0f);
ImGui::Text("Position");
ImGui::SameLine(80);
ImGui::SetNextItemWidth(180);
ImGui::DragFloat3("##Position", transform->position, 0.1f);
ImGui::Text("Rotation");
ImGui::SameLine(80);
ImGui::SetNextItemWidth(180);
ImGui::DragFloat3("##Rotation", transform->rotation, 1.0f);
ImGui::Text("Scale");
ImGui::SameLine(80);
ImGui::SetNextItemWidth(180);
ImGui::DragFloat3("##Scale", transform->scale, 0.1f);
ImGui::Unindent(10.0f);
}
}
void InspectorPanel::RenderMeshRendererSection(MeshRendererComponent* meshRenderer) {
if (ImGui::CollapsingHeader("Mesh Renderer", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent(10.0f);
ImGui::Text("Material");
ImGui::SameLine(80);
ImGui::SetNextItemWidth(180);
ImGui::InputText("##Material", meshRenderer->materialName.data(), meshRenderer->materialName.capacity());
ImGui::Text("Mesh");
ImGui::SameLine(80);
ImGui::SetNextItemWidth(180);
ImGui::InputText("##Mesh", meshRenderer->meshName.data(), meshRenderer->meshName.capacity());
ImGui::Unindent(10.0f);
}
}
}