add World.Relate + Spawner object
parent
4ff546538b
commit
02ccc3d1a5
|
@ -0,0 +1,16 @@
|
|||
namespace MoonTools.ECS
|
||||
{
|
||||
public abstract class Spawner
|
||||
{
|
||||
private World World;
|
||||
|
||||
public Spawner(World world)
|
||||
{
|
||||
World = world;
|
||||
}
|
||||
|
||||
protected Entity CreateEntity() => World.CreateEntity();
|
||||
protected void Set<TComponent>(in Entity entity, in TComponent component) where TComponent : unmanaged => World.Set<TComponent>(entity, component);
|
||||
protected void Relate<TRelationKind>(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged => World.Relate(entityA, entityB, relationData);
|
||||
}
|
||||
}
|
|
@ -69,13 +69,7 @@ namespace MoonTools.ECS
|
|||
MessageDepot.Add(entity.ID, message);
|
||||
}
|
||||
|
||||
protected void Relate<TRelationKind>(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged
|
||||
{
|
||||
RelationDepot.Set(entityA, entityB, relationData);
|
||||
var relationTypeIndex = RelationTypeIndices.GetIndex<TRelationKind>();
|
||||
EntityStorage.AddRelationKind(entityA.ID, relationTypeIndex);
|
||||
EntityStorage.AddRelationKind(entityB.ID, relationTypeIndex);
|
||||
}
|
||||
protected void Relate<TRelationKind>(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged => World.Relate(entityA, entityB, relationData);
|
||||
|
||||
protected void Unrelate<TRelationKind>(in Entity entityA, in Entity entityB) where TRelationKind : unmanaged
|
||||
{
|
||||
|
|
|
@ -78,6 +78,14 @@ namespace MoonTools.ECS
|
|||
MessageDepot.Add(message);
|
||||
}
|
||||
|
||||
public void Relate<TRelationKind>(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged
|
||||
{
|
||||
RelationDepot.Set(entityA, entityB, relationData);
|
||||
var relationTypeIndex = RelationTypeIndices.GetIndex<TRelationKind>();
|
||||
EntityStorage.AddRelationKind(entityA.ID, relationTypeIndex);
|
||||
EntityStorage.AddRelationKind(entityB.ID, relationTypeIndex);
|
||||
}
|
||||
|
||||
public void Destroy(in Entity entity)
|
||||
{
|
||||
foreach (var componentTypeIndex in EntityStorage.ComponentTypeIndices(entity.ID))
|
||||
|
|
Loading…
Reference in New Issue