Files
MonoGame.Extended/Source/MonoGame.Extended.Entities/Systems/EntityUpdateSystem.cs
T

37 lines
1.2 KiB
C#

using MonoGame.Extended.Collections;
namespace MonoGame.Extended.Entities.Systems
{
public abstract class EntityUpdateSystem : UpdateSystem
{
protected EntityUpdateSystem(AspectBuilder aspectBuilder)
{
_aspectBuilder = aspectBuilder;
}
private readonly AspectBuilder _aspectBuilder;
private EntitySubscription _subscription;
private EntityWorld _world;
public EntityWorld World
{
get => _world;
internal set
{
_world = value;
_subscription = new EntitySubscription(_world.EntityManager, _aspectBuilder.Build(_world.ComponentManager));
// TODO: Undisposed events.
_world.EntityManager.EntityAdded += (sender, entityId) => OnEntityAdded(entityId);
_world.EntityManager.EntityRemoved += (sender, entityId) => OnEntityRemoved(entityId);
}
}
protected virtual void OnEntityAdded(int entityId) { }
protected virtual void OnEntityRemoved(int entityId) { }
public Bag<int> ActiveEntities => _subscription.ActiveEntities;
public abstract void Initialize(IComponentMapperService mapperService);
}
}