- Editor CMakeLists.txt 链接 XCEngine 库 - 删除 editor/src/Core/GameObject.h (简化版) - SelectionManager 使用 Engine::Components::GameObject* - SceneManager 使用 Engine::Scene - HierarchyPanel 使用 Engine GameObject API - InspectorPanel 使用 Engine TransformComponent 注意: Engine RHI Shader 接口有编译错误需要修复
77 lines
2.3 KiB
C++
77 lines
2.3 KiB
C++
#include "InspectorPanel.h"
|
|
#include "Managers/SceneManager.h"
|
|
#include "Managers/SelectionManager.h"
|
|
#include <imgui.h>
|
|
#include <string>
|
|
#include <glm/glm.hpp>
|
|
|
|
namespace UI {
|
|
|
|
InspectorPanel::InspectorPanel() : Panel("Inspector") {
|
|
m_selectionHandlerId = SelectionManager::Get().OnSelectionChanged.Subscribe([this](uint64_t) {
|
|
});
|
|
}
|
|
|
|
InspectorPanel::~InspectorPanel() {
|
|
SelectionManager::Get().OnSelectionChanged.Unsubscribe(m_selectionHandlerId);
|
|
}
|
|
|
|
void InspectorPanel::Render() {
|
|
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
|
|
|
XCEngine::Components::GameObject* entity = SelectionManager::Get().GetSelectedEntity();
|
|
|
|
if (entity) {
|
|
RenderEntity(entity);
|
|
} 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::RenderEntity(XCEngine::Components::GameObject* entity) {
|
|
ImGui::Text("%s", entity->GetName().c_str());
|
|
ImGui::Separator();
|
|
|
|
for (auto& component : entity->m_components) {
|
|
RenderComponent(component.get());
|
|
ImGui::Separator();
|
|
}
|
|
}
|
|
|
|
void InspectorPanel::RenderComponent(XCEngine::Components::Component* component) {
|
|
if (!component) return;
|
|
|
|
const char* name = component->GetName().c_str();
|
|
|
|
std::string headerId = std::string(name) + "##" + std::to_string(reinterpret_cast<uintptr_t>(component));
|
|
|
|
if (ImGui::CollapsingHeader(headerId.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
ImGui::Indent(10.0f);
|
|
|
|
if (auto* transform = dynamic_cast<XCEngine::Components::TransformComponent*>(component)) {
|
|
glm::vec3 position = transform->GetLocalPosition();
|
|
glm::vec3 rotation = transform->GetLocalEulerAngles();
|
|
glm::vec3 scale = transform->GetLocalScale();
|
|
|
|
if (ImGui::DragFloat3("Position", &position.x, 0.1f)) {
|
|
transform->SetLocalPosition(position);
|
|
}
|
|
|
|
if (ImGui::DragFloat3("Rotation", &rotation.x, 1.0f)) {
|
|
transform->SetLocalEulerAngles(rotation);
|
|
}
|
|
|
|
if (ImGui::DragFloat3("Scale", &scale.x, 0.1f)) {
|
|
transform->SetLocalScale(scale);
|
|
}
|
|
}
|
|
|
|
ImGui::Unindent(10.0f);
|
|
}
|
|
}
|
|
|
|
}
|