Really basic component inspection
This commit is contained in:
@@ -96,6 +96,7 @@ namespace Nerfed.Editor.Systems
|
||||
|
||||
if (ImGui.TreeNodeEx($"{entity.ID} | {GetTag(entity)}", flags))
|
||||
{
|
||||
// TODO: fix selection, look at ImGui 1.91, https://github.com/ocornut/imgui/wiki/Multi-Select
|
||||
// Selection.
|
||||
if (ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen())
|
||||
{
|
||||
|
56
Nerfed.Editor/Systems/EditorInspectorWindow.cs
Normal file
56
Nerfed.Editor/Systems/EditorInspectorWindow.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
Reference in New Issue
Block a user