#include "InspectorPanel.h" #include "Managers/SceneManager.h" #include "Managers/SelectionManager.h" #include #include #include 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(component)); if (ImGui::CollapsingHeader(headerId.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Indent(10.0f); if (auto* transform = dynamic_cast(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); } } }