Entitas-0.32.0
Public Member Functions | Public Attributes | Properties | Events | List of all members
Entitas.Entity Class Reference

Public Member Functions

delegate void EntityChanged (Entity entity, int index, IComponent component)
 
delegate void ComponentReplaced (Entity entity, int index, IComponent previousComponent, IComponent newComponent)
 
delegate void EntityReleased (Entity entity)
 
 Entity (int totalComponents, Stack< IComponent >[] componentPools, PoolMetaData poolMetaData=null)
 Use pool.CreateEntity() to create a new entity and pool.DestroyEntity() to destroy it.
 
Entity AddComponent (int index, IComponent component)
 
Entity RemoveComponent (int index)
 
Entity ReplaceComponent (int index, IComponent component)
 
IComponent GetComponent (int index)
 
IComponent[] GetComponents ()
 Returns all added components.
 
int[] GetComponentIndices ()
 Returns all indices of added components.
 
bool HasComponent (int index)
 Determines whether this entity has a component at the specified index.
 
bool HasComponents (int[] indices)
 Determines whether this entity has components at all the specified indices.
 
bool HasAnyComponent (int[] indices)
 Determines whether this entity has a component at any of the specified indices.
 
void RemoveAllComponents ()
 Removes all components.
 
Stack< IComponent > GetComponentPool (int index)
 
IComponent CreateComponent (int index, Type type)
 Returns a new or reusable component from the componentPool for the specified component index.
 
CreateComponent< T > (int index)
 Returns a new or reusable component from the componentPool for the specified component index.
 
Entity Retain (object owner)
 
void Release (object owner)
 
override string ToString ()
 

Public Attributes

readonly HashSet< object > owners = new HashSet<object>()
 Returns all the objects that retain this entity.
 

Properties

int totalComponents [get]
 The total amount of components an entity can possibly have.
 
int creationIndex [get]
 Each entity has its own unique creationIndex which will be set by the pool when you create the entity.
 
bool isEnabled [get]
 The pool manages the state of an entity. Active entities are enabled, destroyed entities are not.
 
Stack< IComponent >[] componentPools [get]
 
PoolMetaData poolMetaData [get]
 
int retainCount [get]
 Returns the number of objects that retain this entity.
 

Events

EntityChanged OnComponentAdded
 Occurs when a component gets added. All event handlers will be removed when the entity gets destroyed by the pool.
 
EntityChanged OnComponentRemoved
 Occurs when a component gets removed. All event handlers will be removed when the entity gets destroyed by the pool.
 
ComponentReplaced OnComponentReplaced
 Occurs when a component gets replaced. All event handlers will be removed when the entity gets destroyed by the pool.
 
EntityReleased OnEntityReleased
 Occurs when an entity gets released and is not retained anymore. All event handlers will be removed when the entity gets destroyed by the pool.
 

Detailed Description

Use pool.CreateEntity() to create a new entity and pool.DestroyEntity() to destroy it. You can add, replace and remove IComponent to an entity.

Member Function Documentation

Entity Entitas.Entity.AddComponent ( int  index,
IComponent  component 
)
inline

Adds a component at the specified index. You can only have one component at an index. Each component type must have its own constant index. The prefered way is to use the generated methods from the code generator.

IComponent Entitas.Entity.GetComponent ( int  index)
inline

Returns a component at the specified index. You can only get a component at an index if it exists. The prefered way is to use the generated methods from the code generator.

Stack<IComponent> Entitas.Entity.GetComponentPool ( int  index)
inline

Returns the componentPool for the specified component index. componentPools is set by the pool which created the entity and is used to reuse removed components. Removed components will be pushed to the componentPool. Use entity.CreateComponent(index, type) to get a new or reusable component from the componentPool.

void Entitas.Entity.Release ( object  owner)
inline

Releases the entity. An owner can only release an entity if it retains it. Retain/Release is part of AERC (Automatic Entity Reference Counting) and is used internally to prevent pooling retained entities. If you use retain manually you also have to release it manually at some point.

Entity Entitas.Entity.RemoveComponent ( int  index)
inline

Removes a component at the specified index. You can only remove a component at an index if it exists. The prefered way is to use the generated methods from the code generator.

Entity Entitas.Entity.ReplaceComponent ( int  index,
IComponent  component 
)
inline

Replaces an existing component at the specified index or adds it if it doesn't exist yet. The prefered way is to use the generated methods from the code generator.

Entity Entitas.Entity.Retain ( object  owner)
inline

Retains the entity. An owner can only retain the same entity once. Retain/Release is part of AERC (Automatic Entity Reference Counting) and is used internally to prevent pooling retained entities. If you use retain manually you also have to release it manually at some point.

override string Entitas.Entity.ToString ( )
inline

Returns a cached string to describe the entity with the following format: Entity_{creationIndex}(*{retainCount})({list of components})

Property Documentation

Stack<IComponent> [] Entitas.Entity.componentPools
get

componentPools is set by the pool which created the entity and is used to reuse removed components. Removed components will be pushed to the componentPool. Use entity.CreateComponent(index, type) to get a new or reusable component from the componentPool. Use entity.GetComponentPool(index) to get a componentPool for a specific component index.

PoolMetaData Entitas.Entity.poolMetaData
get

The poolMetaData is set by the pool which created the entity and contains information about the pool. It's used to provide better error messages.


The documentation for this class was generated from the following file: