Class EntityManager
Collects every Entity instance present in a Scene. As a collection, it supports common operations such as adding and removing entities.
Implements
Inherited Members
Namespace: Evergine.Framework.Managers
Assembly: Evergine.Framework.dll
Syntax
public class EntityManager : SceneManager, IDependencyObject
Constructors
EntityManager()
Initializes a new instance of the EntityManager class.
Declaration
public EntityManager()
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if adapter or scene is null. |
Properties
AllEntities
Declaration
public IEnumerable<Entity> AllEntities { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Entity> | Every Entity instance. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | EntityManager has been disposed. |
Count
Gets how many Entity instances have been added to this instance.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int | The number of Entity instances added to this instance. |
EntityGraph
Gets the Entity instances
(see
Declaration
public IEnumerable<Entity> EntityGraph { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Entity> | The Entity instances. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | EntityManager has been disposed. |
Methods
Add(Entity)
Adds a new Entity to this instance.
Declaration
public virtual void Add(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The Entity to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the entity is null. |
InvalidOperationException | Thrown if there is already an entity added to this instance with the same name. |
Add(IEnumerable<Entity>)
Adds a list of Entity to EntityManager.
Declaration
public virtual void Add(IEnumerable<Entity> newEntities)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Entity> | newEntities | The Entity list to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If newEntities are null. |
InvalidOperationException | If there is already an entity added to this instance with the same name. |
Contains(Entity)
Declaration
public bool Contains(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The Entity to check. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the entity is null. |
Detach(Entity)
Detaches a specific entity.
Declaration
public bool Detach(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity to detach. |
Returns
Type | Description |
---|---|
bool | Indicates whether an entity was detached. |
Remarks
The entity is disposed
when it is detached from this instance.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if entity is null. |
Find(Guid)
Looks for an Entity entity in the EntityGraph, through its name.
Declaration
public Entity Find(Guid entityId)
Parameters
Type | Name | Description |
---|---|---|
Guid | entityId | The entity Id to find. |
Returns
Type | Description |
---|---|
Entity | The Entity with the specified |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the entity id is an empty Guid. |
Find(string, Entity)
Finds the first entity in the EntityGraph with the given entity path.
Declaration
public Entity Find(string entityPath, Entity sourceEntity = null)
Parameters
Type | Name | Description |
---|---|---|
string | entityPath | Path of the entity to look for. If |
Entity | sourceEntity | The source entity for a relative path. |
Returns
Type | Description |
---|---|
Entity | The Entity with the specified |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the name is null or empty. |
FindAllByTag(string)
Finds all entities with the same tag
in the
Declaration
public IEnumerable<Entity> FindAllByTag(string tag)
Parameters
Type | Name | Description |
---|---|---|
string | tag | The tag. |
Returns
Type | Description |
---|---|
IEnumerable<Entity> | All entities with the same |
FindComponentFromEntityPath<T>(string, bool)
Returns the first component inside the first entity with the given entity path.
Declaration
public T FindComponentFromEntityPath<T>(string entityPath, bool isExactType = true) where T : Component
Parameters
Type | Name | Description |
---|---|---|
string | entityPath | Entity path. |
bool | isExactType | If set to |
Returns
Type | Description |
---|---|
T | Component inside the entity. |
Type Parameters
Name | Description |
---|---|
T | Component type. |
FindComponentsFromEntityPath<T>(string, bool)
Returns the components inside the first entity with the given entity path.
Declaration
public IEnumerable<T> FindComponentsFromEntityPath<T>(string entityPath, bool isExactType = true) where T : Component
Parameters
Type | Name | Description |
---|---|---|
string | entityPath | Entity Path. |
bool | isExactType | If set to |
Returns
Type | Description |
---|---|
IEnumerable<T> | Components collection. |
Type Parameters
Name | Description |
---|---|
T | Component Type. |
FindComponentsOfType(Type, bool, string)
Iterate through the entire entity hierarchy and return all component instances of the specified type.
Declaration
public IEnumerable<Component> FindComponentsOfType(Type type, bool isExactType = true, string tag = null)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The component type. |
bool | isExactType | Whether to match the exact type. |
string | tag | Filter entities by this tag. |
Returns
Type | Description |
---|---|
IEnumerable<Component> | The component enumerable. |
Remarks
This method is extremely slow; try not to use it inside an Update method.
FindComponentsOfType<T>(bool, string)
Iterate through the entire entity hierarchy and return all component instances of the specified type.
Declaration
public IEnumerable<T> FindComponentsOfType<T>(bool isExactType = true, string tag = null) where T : Component
Parameters
Type | Name | Description |
---|---|---|
bool | isExactType | Whether to match the exact type. |
string | tag | Filter entities by this tag. |
Returns
Type | Description |
---|---|
IEnumerable<T> | The component enumerable. |
Type Parameters
Name | Description |
---|---|
T | The component type. |
Remarks
This method is extremely slow; try not to use it inside an Update method.
FindFirstComponentOfType(Type, bool, string)
Iterate through the entire entity hierarchy and return the first component instance of the specified type.
Declaration
public Component FindFirstComponentOfType(Type type, bool isExactType = true, string tag = null)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The component type. |
bool | isExactType | Whether to match the exact type. |
string | tag | Filter entities by this tag. |
Returns
Type | Description |
---|---|
Component | The component. |
Remarks
This method is extremely slow, try to avoid using it inside an Update method.
FindFirstComponentOfType<T>(bool, string)
Iterate through the entire entity hierarchy and return the first component instance of the specified type.
Declaration
public T FindFirstComponentOfType<T>(bool isExactType = true, string tag = null) where T : Component
Parameters
Type | Name | Description |
---|---|---|
bool | isExactType | if set to |
string | tag | Filter entities by this tag. |
Returns
Type | Description |
---|---|
T | The component. |
Type Parameters
Name | Description |
---|---|
T | The component type. |
Remarks
This method is extremely slow, try to avoid using it inside an Update method.
GetEntityTagCollection(string)
Gets a collection of entities filtered by the specified tag.
Declaration
public virtual EntityManager.EntityTagCollection GetEntityTagCollection(string tag)
Parameters
Type | Name | Description |
---|---|---|
string | tag | The tag. |
Returns
Type | Description |
---|---|
EntityManager.EntityTagCollection | The entity tag collection. |
OnActivated()
Invoked when the object is activated once it is attached.
Declaration
protected override void OnActivated()
Overrides
OnDetach()
Invoked when the object is detached.
Declaration
protected override void OnDetach()
Overrides
Remove(Entity)
Removes a specific entity.
Declaration
public virtual bool Remove(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity to remove. |
Returns
Type | Description |
---|---|
bool | Whether an entity was removed. |
Remarks
The entity is disposed
when it is removed from this instance.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the entity is null. |
Start()
Invoked to start the object.
Declaration
protected override void Start()
Overrides
Events
EntityAdded
Occurs when an Entity is added.
Declaration
public event EventHandler<Entity> EntityAdded
Event Type
Type | Description |
---|---|
EventHandler<Entity> |
EntityDetached
Occurs when an Entity is detached.
Note that even when removing an entity, the entity is detached first. Therefore, this event will be fired for removed entities as well.
Declaration
public event EventHandler<Entity> EntityDetached
Event Type
Type | Description |
---|---|
EventHandler<Entity> |