hierachy and parent child system updates
- started working on an editor hierarchy window - testing filters - testing parent child relations without system - testing root component - thinking about how to get all entities that are not a child, but also don't have an other identifying component
This commit is contained in:
@@ -66,6 +66,11 @@ namespace Nerfed.Editor
|
||||
UpdateDock();
|
||||
|
||||
ImGui.ShowDemoWindow();
|
||||
|
||||
foreach (MoonTools.ECS.System system in Program.editorSystems)
|
||||
{
|
||||
system.Update(Engine.Timestep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using MoonTools.ECS;
|
||||
using Nerfed.Editor.Systems;
|
||||
using Nerfed.Runtime;
|
||||
using Nerfed.Runtime.Components;
|
||||
using Nerfed.Runtime.Systems;
|
||||
using Nerfed.Runtime.Util;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Nerfed.Editor;
|
||||
@@ -10,6 +12,7 @@ internal class Program
|
||||
{
|
||||
private static readonly World world = new World();
|
||||
private static List<MoonTools.ECS.System> systems = new List<MoonTools.ECS.System>();
|
||||
public static List<MoonTools.ECS.System> editorSystems = new List<MoonTools.ECS.System>();
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
@@ -23,15 +26,25 @@ internal class Program
|
||||
|
||||
private static void HandleOnInitialize()
|
||||
{
|
||||
systems.Add(new ParentSystem(world));
|
||||
//systems.Add(new ParentSystem(world));
|
||||
systems.Add(new LocalToWorldSystem(world));
|
||||
editorSystems.Add(new EditorHierarchyWindow(world));
|
||||
|
||||
Entity ent1 = world.CreateEntity();
|
||||
Entity ent1 = world.CreateEntity("parent");
|
||||
world.Set(ent1, new LocalTransform(new Vector3(1, 0, 0), Quaternion.Identity, Vector3.One));
|
||||
|
||||
Entity ent2 = world.CreateEntity();
|
||||
Entity ent2 = world.CreateEntity("child");
|
||||
world.Set(ent2, new LocalTransform(new Vector3(0, 1, 0), Quaternion.Identity, Vector3.One));
|
||||
world.Set(ent2, new Parent(ent1));
|
||||
Transform.SetParent(world, ent2, ent1);
|
||||
|
||||
Entity ent3 = world.CreateEntity("entity3");
|
||||
world.Set(ent3, new Root());
|
||||
Transform.SetParent(world, ent3, ent2);
|
||||
|
||||
Entity ent4 = world.CreateEntity("entity4");
|
||||
world.Set(ent4, new Root());
|
||||
|
||||
Entity ent5 = world.CreateBaseEntity("entity5");
|
||||
|
||||
// Open project.
|
||||
// Setip EditorGui.
|
||||
@@ -50,6 +63,8 @@ internal class Program
|
||||
|
||||
|
||||
// Try Catch UserCode Update.
|
||||
|
||||
world.FinishUpdate();
|
||||
}
|
||||
|
||||
private static void HandleOnRender()
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using ImGuiNET;
|
||||
using MoonTools.ECS;
|
||||
using Nerfed.Runtime.Components;
|
||||
|
||||
namespace Nerfed.Editor.Systems
|
||||
{
|
||||
internal class EditorHierarchyWindow : MoonTools.ECS.DebugSystem
|
||||
{
|
||||
private readonly Filter rootEntitiesWithTransformFilter;
|
||||
private readonly Filter rootEntitiesFilterBroken;
|
||||
private readonly Filter rootEntitiesFilter;
|
||||
|
||||
public EditorHierarchyWindow(World world) : base(world)
|
||||
{
|
||||
rootEntitiesWithTransformFilter = FilterBuilder.Include<LocalTransform>().Exclude<Child>().Build();
|
||||
|
||||
// TODO: this doesn't work.
|
||||
rootEntitiesFilterBroken = FilterBuilder.Exclude<Child>().Build();
|
||||
|
||||
// Maybe the parent/child functions should add a root component when not being a child.
|
||||
rootEntitiesFilter = FilterBuilder.Include<Root>().Build();
|
||||
|
||||
// Maybe instead of a root, if we need a component that is always on an entity and has some use we could create something like a VersionComponent which only hold an int.
|
||||
// The version would update each time something changes on the entity.
|
||||
//
|
||||
}
|
||||
|
||||
public override void Update(TimeSpan delta)
|
||||
{
|
||||
ImGui.Begin("Hierarchy");
|
||||
|
||||
foreach (Entity entity in rootEntitiesWithTransformFilter.Entities)
|
||||
{
|
||||
DrawEntityAndChildren(entity);
|
||||
}
|
||||
|
||||
ImGui.NewLine();
|
||||
|
||||
foreach (Entity entity in rootEntitiesFilter.Entities)
|
||||
{
|
||||
DrawEntityAndChildren(entity);
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
private void DrawEntityAndChildren(in Entity entity, int depth = 0)
|
||||
{
|
||||
string label = new string(' ', depth);
|
||||
ImGui.Text($"{label}{entity.ID} | {GetTag(entity)}");
|
||||
|
||||
depth++;
|
||||
ReverseSpanEnumerator<Entity> childEntities = World.InRelations<ChildParentRelation>(entity);
|
||||
foreach (Entity childEntity in childEntities)
|
||||
{
|
||||
DrawEntityAndChildren(childEntity, depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user