Nerfed/Nerfed.Editor/Systems/EditorInspectorWindow.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2024-10-22 23:54:36 +02:00
using ImGuiNET;
using MoonTools.ECS;
using Nerfed.Editor.Components;
#if DEBUG
namespace Nerfed.Editor.Systems
{
// Window that draws entities.
internal class EditorInspectorWindow : MoonTools.ECS.DebugSystem
{
private readonly Filter selectedEntityFilter;
public EditorInspectorWindow(World world) : base(world)
{
selectedEntityFilter = FilterBuilder.Include<SelectedInHierachy>().Build();
}
public override void Update(TimeSpan delta)
{
ImGui.Begin("Inspector");
foreach (Entity entity in selectedEntityFilter.Entities)
{
DrawEntityComponents(entity);
}
ImGui.End();
}
private void DrawEntityComponents(Entity entity)
{
World.ComponentTypeEnumerator components = World.Debug_GetAllComponentTypes(entity);
foreach (Type type in components)
{
ImGui.Text(type.Name);
}
ImGui.Separator();
// TODO: explore something without reflection.
// Maybe generate some look up dictionary<type, Action<world, entity>> for 'custom editors'.
// Look into serializing of entities and components.
foreach (Type component in components)
{
System.Reflection.MethodInfo getMethodInfo = typeof(World).GetMethod("Get");
System.Reflection.MethodInfo getComponentMethod = getMethodInfo.MakeGenericMethod(component);
object result = getComponentMethod.Invoke(World, [entity]);
// process here
ImGui.Text(result.ToString());
}
}
}
}
#endif