HierarchyPanel walks IWorld.Roots/GameObject.Children recursively as ImGui tree nodes, clicking one sets EditorState.Selected — the shared selection the not-yet-built Inspector panel will read from the same instance. PushID(go.GetHashCode()) scopes each node's ID by object identity rather than name, since nothing stops two sibling GameObjects sharing a Name and ImGui's default label-based IDs would otherwise merge their open/selected state. Also gives samples/WindowDemo/scene.json a child GameObject (offset, half-scale, parented under Quad) — the existing scene only had one root, nothing to show a tree with. Verified by screenshot: both quads render at their correct composed WorldMatrix (the child visibly smaller and offset, confirming parent/child composition is still correct through this change), and Hierarchy lists "Quad" as a collapsible node. Full suite still green: 65 tests. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1qPfzq8TDCUMFMV3UwV5N
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Engine.Kernel.World;
|
|
using ImGuiNET;
|
|
|
|
namespace Engine.Editor;
|
|
|
|
/// <summary>
|
|
/// Walks IWorld.Roots/GameObject.Children directly — not Query<T>(),
|
|
/// there's no component type to query for here — so, like EditorPlugin
|
|
/// itself, this never touches SystemAccessScope and needs no declared
|
|
/// Reads/Writes.
|
|
/// </summary>
|
|
internal static class HierarchyPanel
|
|
{
|
|
public static void Draw(IWorld world, EditorState state)
|
|
{
|
|
ImGui.Begin("Hierarchy");
|
|
|
|
foreach (var root in world.Roots)
|
|
DrawNode(root, state);
|
|
|
|
ImGui.End();
|
|
}
|
|
|
|
private static void DrawNode(GameObject go, EditorState state)
|
|
{
|
|
// PushID/PopID, not relying on go.Name for identity: sibling
|
|
// GameObjects can share a name (nothing stops it), and ImGui's
|
|
// default ID-from-label would then merge their open/selected state.
|
|
ImGui.PushID(go.GetHashCode());
|
|
|
|
var flags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.SpanAvailWidth;
|
|
if (go.Children.Count == 0)
|
|
flags |= ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen;
|
|
if (ReferenceEquals(state.Selected, go))
|
|
flags |= ImGuiTreeNodeFlags.Selected;
|
|
|
|
var open = ImGui.TreeNodeEx(go.Name, flags);
|
|
if (ImGui.IsItemClicked())
|
|
state.Selected = go;
|
|
|
|
if (open && go.Children.Count > 0)
|
|
{
|
|
foreach (var child in go.Children)
|
|
DrawNode(child, state);
|
|
ImGui.TreePop();
|
|
}
|
|
|
|
ImGui.PopID();
|
|
}
|
|
}
|