diff --git a/src/ECS/Entity.cs b/src/ECS/Entity.cs
index e5cddd57..febf3dc1 100644
--- a/src/ECS/Entity.cs
+++ b/src/ECS/Entity.cs
@@ -257,7 +257,7 @@ public ref readonly Tags Tags { get {
[Browse(Never)] public EntityData Data { get {
ref var node = ref store.nodes[Id];
if (node.archetype != null && Revision == node.revision) {
- return new EntityData(node);
+ return new EntityData(node, Id);
}
return default;
} }
diff --git a/src/ECS/Entity/EntityData.cs b/src/ECS/Entity/EntityData.cs
index 91725895..cfce03c5 100644
--- a/src/ECS/Entity/EntityData.cs
+++ b/src/ECS/Entity/EntityData.cs
@@ -2,7 +2,10 @@
// See LICENSE file in the project root for full license information.
using System;
+using static System.Diagnostics.DebuggerBrowsableState;
+using Browse = System.Diagnostics.DebuggerBrowsableAttribute;
+// ReSharper disable InconsistentNaming
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS;
@@ -15,20 +18,33 @@ namespace Friflo.Engine.ECS;
///
public readonly ref struct EntityData
{
-#region entity getter
- /// Returns true is the entity is deleted.
- /// Executes in O(1)
- public bool IsNull => archetype == null;
-
+#region entity properties
/// Return the added to an entity.
/// if the entity is deleted.
/// Executes in O(1)
- public Tags Tags => archetype.tags;
+ public Tags Tags => archetype.tags;
+
+ /// Returns true is the entity is deleted.
+ /// Executes in O(1)
+ [Browse(Never)] public bool IsNull => archetype == null;
/// Returns the archetype the entity belongs to.
- public Archetype Archetype => archetype;
+ [Browse(Never)] public Archetype Archetype => archetype;
+
+ /// Return the 's added to the entity.
+ public EntityComponents Components => new EntityComponents(new Entity(archetype.entityStore, Id));
+ public override string ToString() => $"Id: {Id}";
+#endregion
+
+#region fields
+ [Browse(Never)] private readonly StructHeap[] heapMap;
+ [Browse(Never)] private readonly Archetype archetype;
+ public readonly int Id;
+ [Browse(Never)] private readonly int compIndex;
+ #endregion
+#region entity getter
/// Returns true if the entity contains a component of the specified type.
public bool Has () where T : struct, IComponent {
return heapMap[StructInfo.Index] != null;
@@ -58,16 +74,14 @@ public bool TryGet(out T value) where T : struct, IComponent {
}
#endregion
-#region fields
- private readonly StructHeap[] heapMap;
- private readonly Archetype archetype;
- private readonly int compIndex;
-#endregion
- internal EntityData(in EntityNode node) {
+#region methods
+ internal EntityData(in EntityNode node, int id) {
var type = node.archetype;
heapMap = type.heapMap;
archetype = type;
+ Id = id;
compIndex = node.compIndex;
}
+ #endregion
}
\ No newline at end of file
diff --git a/src/Tests/ECS/Entity/Test_EntityData.cs b/src/Tests/ECS/Entity/Test_EntityData.cs
index d2d44059..f20ee2e2 100644
--- a/src/Tests/ECS/Entity/Test_EntityData.cs
+++ b/src/Tests/ECS/Entity/Test_EntityData.cs
@@ -11,6 +11,7 @@ namespace Tests.ECS {
public static class Test_EntityState
{
+#pragma warning disable CS0618 // Type or member is obsolete
[Test]
public static void Test_EntityData_access()
{
@@ -24,6 +25,8 @@ public static void Test_EntityData_access()
IsTrue(tags.Has());
IsTrue(tags.Has());
+ AreEqual(1, data.Id);
+ AreEqual("Id: 1", data.ToString());
AreSame (entity.Archetype, data.Archetype);
AreEqual(new Position(1,2,3), data.Get());
IsTrue ( data.Has());
@@ -35,6 +38,19 @@ public static void Test_EntityData_access()
IsFalse( data.Has());
IsFalse( data.TryGet(out _));
+ var components = data.Components;
+ AreEqual(2, components.Count);
+ int count = 0;
+ foreach (var component in components)
+ {
+ var value = component.Value;
+ switch (count++) {
+ case 0: AreEqual("test", ((EntityName)value).value); break;
+ case 1: AreEqual(new Position(1,2,3), (Position)value); break;
+ }
+ }
+ AreEqual(2, count);
+
entity.DeleteEntity();
data = entity.Data;
@@ -46,7 +62,7 @@ public static void Test_EntityData_access()
GetComponent(entity);
});
}
-
+#pragma warning restore CS0618 // Type or member is obsolete
private static void GetTags(Entity entity) {
var state = entity.Data;