Entitas  0.35.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
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)
 
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)
 
bool HasComponents (int[] indices)
 
bool HasAnyComponent (int[] indices)
 
void RemoveAllComponents ()
 Removes all components.
 
Stack< IComponentGetComponentPool (int index)
 
IComponent CreateComponent (int index, Type type)
 
CreateComponent< T > (int index)
 
Entity Retain (object owner)
 
void Release (object owner)
 
override string ToString ()
 
Entity ApplyBlueprint (Blueprint blueprint, bool replaceComponents=false)
 

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]
 
bool isEnabled [get]
 
Stack< IComponent > [] componentPools [get]
 
PoolMetaData poolMetaData [get]
 
int retainCount [get]
 Returns the number of objects that retain this entity.
 

Events

EntityChanged OnComponentAdded
 
EntityChanged OnComponentRemoved
 
ComponentReplaced OnComponentReplaced
 
EntityReleased OnEntityReleased
 

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.

Definition at line 10 of file Entity.cs.

Constructor & Destructor Documentation

§ Entity()

Entitas.Entity.Entity ( int  totalComponents,
Stack< IComponent > []  componentPools,
PoolMetaData  poolMetaData = null 
)
inline

Use pool.CreateEntity() to create a new entity and pool.DestroyEntity() to destroy it.

Definition at line 84 of file Entity.cs.

Member Function Documentation

§ AddComponent()

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.

Definition at line 114 of file Entity.cs.

§ ApplyBlueprint()

Entity Entitas.Entity.ApplyBlueprint ( Blueprint  blueprint,
bool  replaceComponents = false 
)
inline

Adds all components from the blueprint to the entity. When 'replaceComponents' is set to true entity.ReplaceComponent() will be used instead of entity.AddComponent().

Definition at line 10 of file BlueprintEntityExtension.cs.

§ CreateComponent()

IComponent Entitas.Entity.CreateComponent ( int  index,
Type  type 
)
inline

Returns a new or reusable component from the componentPool for the specified component index.

Definition at line 342 of file Entity.cs.

§ CreateComponent< T >()

T Entitas.Entity.CreateComponent< T > ( int  index)
inline

Returns a new or reusable component from the componentPool for the specified component index.

Type Constraints
T :new() 

Definition at line 351 of file Entity.cs.

§ GetComponent()

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.

Definition at line 230 of file Entity.cs.

§ GetComponentPool()

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.

Definition at line 330 of file Entity.cs.

§ HasAnyComponent()

bool Entitas.Entity.HasAnyComponent ( int []  indices)
inline

Determines whether this entity has a component at any of the specified indices.

Definition at line 304 of file Entity.cs.

§ HasComponent()

bool Entitas.Entity.HasComponent ( int  index)
inline

Determines whether this entity has a component at the specified index.

Definition at line 286 of file Entity.cs.

§ HasComponents()

bool Entitas.Entity.HasComponents ( int []  indices)
inline

Determines whether this entity has components at all the specified indices.

Definition at line 292 of file Entity.cs.

§ Release()

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.

Definition at line 402 of file Entity.cs.

§ RemoveComponent()

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.

Definition at line 149 of file Entity.cs.

§ ReplaceComponent()

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.

Definition at line 178 of file Entity.cs.

§ Retain()

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.

Definition at line 377 of file Entity.cs.

§ ToString()

override string Entitas.Entity.ToString ( )
inline

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

Definition at line 445 of file Entity.cs.

Property Documentation

§ componentPools

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.

Definition at line 61 of file Entity.cs.

§ creationIndex

int Entitas.Entity.creationIndex
get

Each entity has its own unique creationIndex which will be set by the pool when you create the entity.

Definition at line 48 of file Entity.cs.

§ isEnabled

bool Entitas.Entity.isEnabled
get

The pool manages the state of an entity. Active entities are enabled, destroyed entities are not.

Definition at line 52 of file Entity.cs.

§ poolMetaData

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.

Definition at line 68 of file Entity.cs.

Event Documentation

§ OnComponentAdded

EntityChanged Entitas.Entity.OnComponentAdded

Occurs when a component gets added. All event handlers will be removed when the entity gets destroyed by the pool.

Definition at line 15 of file Entity.cs.

§ OnComponentRemoved

EntityChanged Entitas.Entity.OnComponentRemoved

Occurs when a component gets removed. All event handlers will be removed when the entity gets destroyed by the pool.

Definition at line 20 of file Entity.cs.

§ OnComponentReplaced

ComponentReplaced Entitas.Entity.OnComponentReplaced

Occurs when a component gets replaced. All event handlers will be removed when the entity gets destroyed by the pool.

Definition at line 25 of file Entity.cs.

§ OnEntityReleased

EntityReleased Entitas.Entity.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.

Definition at line 30 of file Entity.cs.


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