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
73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using Engine.Input.Contracts;
|
|
using Engine.Kernel.Diagnostics;
|
|
using Engine.Kernel.Plugins;
|
|
using Engine.Kernel.Scheduling;
|
|
using Engine.Kernel.World;
|
|
using Engine.Windowing.Contracts;
|
|
using ImGuiNET;
|
|
using Silk.NET.OpenGL;
|
|
using Silk.NET.OpenGL.Extensions.ImGui;
|
|
|
|
namespace Engine.Editor;
|
|
|
|
/// <summary>
|
|
/// M3's editor shell: an ImGui overlay drawn on top of the running scene.
|
|
/// Registers on Stage.Render, after engine.render's own Draw (per
|
|
/// project.json's plugin order) so it paints into the same back buffer the
|
|
/// scene just drew into — and before Stage.Present's SwapBuffers, so the
|
|
/// UI isn't delayed a frame. See Stage.Present's doc comment for why that
|
|
/// split exists at all.
|
|
///
|
|
/// Nothing here reads or writes a Component through GetComponent/Query —
|
|
/// HierarchyPanel walks IWorld.Roots/GameObject.Children directly, and the
|
|
/// not-yet-built Inspector will walk GameObject.Components the same way —
|
|
/// which is why this plugin never needs to declare Reads/Writes on its
|
|
/// system: those checks only guard the typed accessors, not plain property
|
|
/// reads. See GameObject.AddComponent's own doc comment on the same gap.
|
|
/// </summary>
|
|
public sealed class EditorPlugin : IPlugin
|
|
{
|
|
private readonly EditorState _state = new();
|
|
private GL? _gl;
|
|
private ImGuiController? _controller;
|
|
private ITime? _time;
|
|
|
|
public void Configure(IPluginContext ctx)
|
|
{
|
|
var window = ctx.Services.Require<IEngineWindow>();
|
|
var input = ctx.Services.Require<IEngineInput>();
|
|
_time = ctx.Time;
|
|
|
|
window.Native.GLContext!.MakeCurrent();
|
|
_gl = window.Native.CreateOpenGL();
|
|
_controller = new ImGuiController(_gl, window.Native, input.Native);
|
|
|
|
ctx.Schedule.Add(Stage.Render, DrawUi);
|
|
ctx.Log.Info("editor UI ready (ImGui)");
|
|
}
|
|
|
|
public void Shutdown(IPluginContext ctx)
|
|
{
|
|
ctx.Schedule.RemoveAllFrom("engine.editor");
|
|
_controller?.Dispose();
|
|
_gl?.Dispose();
|
|
_controller = null;
|
|
_gl = null;
|
|
_time = null;
|
|
}
|
|
|
|
private void DrawUi(IWorld world)
|
|
{
|
|
_controller!.Update(_time!.DeltaTime);
|
|
|
|
ImGui.Begin("Lingua Editor");
|
|
ImGui.Text($"FPS: {1f / MathF.Max(_time.DeltaTime, 0.0001f):F0}");
|
|
ImGui.Text($"Frame: {_time.FrameCount}");
|
|
ImGui.End();
|
|
|
|
HierarchyPanel.Draw(world, _state);
|
|
|
|
_controller.Render();
|
|
}
|
|
}
|