Really basic component inspection
This commit is contained in:
parent
2a351f7b9d
commit
57b42d8daa
@ -30,6 +30,9 @@ private static void HandleOnInitialize()
|
||||
systems.Add(new LocalToWorldSystem(world));
|
||||
editorSystems.Add(new EditorProfilerWindow(world));
|
||||
editorSystems.Add(new EditorHierarchyWindow(world));
|
||||
#if DEBUG
|
||||
editorSystems.Add(new EditorInspectorWindow(world));
|
||||
#endif
|
||||
|
||||
Entity ent1 = world.CreateEntity("parent");
|
||||
world.Set(ent1, new Root());
|
||||
@ -56,7 +59,7 @@ private static void HandleOnInitialize()
|
||||
Entity parent = newEnt;
|
||||
for (int j = 0; j < 2; j++) {
|
||||
Entity newChildEnt = world.CreateEntity();
|
||||
world.Set(newChildEnt, new LocalTransform(new Vector3(j, j, j), Quaternion.Identity, Vector3.One));
|
||||
world.Set(newChildEnt, new LocalTransform(new Vector3(i + j * i, i - j * i, j - i * i), Quaternion.Identity, Vector3.One));
|
||||
Transform.SetParent(world, newChildEnt, parent);
|
||||
parent = newChildEnt;
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ private void DrawEntityAndChildren(in Entity entity)
|
||||
|
||||
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
|
@ -2,18 +2,11 @@
|
||||
|
||||
namespace Nerfed.Runtime.Components
|
||||
{
|
||||
public struct LocalTransform
|
||||
public readonly record struct LocalTransform(Vector3 position, Quaternion rotation, Vector3 scale)
|
||||
{
|
||||
public Vector3 position;
|
||||
public Quaternion rotation;
|
||||
public Vector3 scale;
|
||||
|
||||
public LocalTransform(Vector3 position, Quaternion rotation, Vector3 scale)
|
||||
{
|
||||
this.position = position;
|
||||
this.rotation = rotation;
|
||||
this.scale = scale;
|
||||
}
|
||||
public readonly Vector3 position = position;
|
||||
public readonly Quaternion rotation = rotation;
|
||||
public readonly Vector3 scale = scale;
|
||||
|
||||
public static readonly LocalTransform Identity = new(Vector3.Zero, Quaternion.Identity, Vector3.One);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user