Class EntityManager
Manage a collection of entities.
public abstract class EntityManager : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IReadOnlySet<Entity>, IReadOnlyCollection<Entity>, IEnumerable<Entity>, IEnumerable
- Inheritance
-
EntityManager
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
EntityManager(IServiceRegistry)
Initializes a new instance of the EntityManager class.
protected EntityManager(IServiceRegistry registry)
Parameters
registry
IServiceRegistryThe registry.
Exceptions
- ArgumentNullException
registry
Properties
ComponentTypes
Gets the list of component types from the entities..
public IEnumerable<TypeInfo> ComponentTypes { get; }
Property Value
- IEnumerable<TypeInfo>
The registered component types.
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
- int
The number of elements in the collection.
ExecutionMode
public ExecutionMode ExecutionMode { get; protected set; }
Property Value
Processors
Gets the entity Processors.
public EntityProcessorCollection Processors { get; }
Property Value
Services
Gets the services.
public IServiceRegistry Services { get; }
Property Value
- IServiceRegistry
The services.
Methods
Contains(Entity)
Determines whether this instance contains the specified entity.
public bool Contains(Entity item)
Parameters
item
EntityThe item.
Returns
- bool
true
if this instance contains the specified entity; otherwise,false
.
Draw(RenderContext)
Calls Draw(RenderContext) on all enabled entity processors.
public virtual void Draw(RenderContext context)
Parameters
context
RenderContextThe render context.
GetEnumerator()
Gets the Entity enumerator of this instance.
public HashSet<Entity>.Enumerator GetEnumerator()
Returns
- HashSet<Entity>.Enumerator
The entity enumerator
GetProcessor<TProcessor>()
Gets the first processor of the type TProcessor.
public TProcessor GetProcessor<TProcessor>() where TProcessor : EntityProcessor
Returns
- TProcessor
The first processor of type T or
null
if not found.
Type Parameters
TProcessor
Type of the processor
OnComponentChanged(Entity, int, EntityComponent, EntityComponent)
protected virtual void OnComponentChanged(Entity entity, int index, EntityComponent previousComponent, EntityComponent newComponent)
Parameters
entity
Entityindex
intpreviousComponent
EntityComponentnewComponent
EntityComponent
OnComponentTypeAdded(TypeInfo)
protected virtual void OnComponentTypeAdded(TypeInfo obj)
Parameters
obj
TypeInfo
OnEntityAdded(Entity)
protected virtual void OnEntityAdded(Entity e)
Parameters
e
Entity
OnEntityRemoved(Entity)
protected virtual void OnEntityRemoved(Entity e)
Parameters
e
Entity
Remove(Entity)
Removes the entity from the EntityManager. It works either entity has a parent or not. In conjonction with EntityProcessor, it will remove child entities as well.
public void Remove(Entity entity)
Parameters
entity
EntityThe entity.
Reset()
Removes all entities from the EntityManager.
protected virtual void Reset()
Update(GameTime)
public virtual void Update(GameTime gameTime)
Parameters
gameTime
GameTime
Events
ComponentChanged
Occurs when a component changed for an entity (Added or removed)
public event EventHandler<EntityComponentEventArgs> ComponentChanged
Event Type
ComponentTypeAdded
Occurs when a new component type is added.
public event EventHandler<TypeInfo> ComponentTypeAdded
Event Type
EntityAdded
Occurs when an entity is added.
public event EventHandler<Entity> EntityAdded
Event Type
EntityRemoved
Occurs when an entity is removed.
public event EventHandler<Entity> EntityRemoved
Event Type
HierarchyChanged
Occurs when an entity is removed.
public event EventHandler<Entity> HierarchyChanged