Entitas Redux
JCMG.EntitasRedux.Entity Class Reference

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

Inheritance diagram for JCMG.EntitasRedux.Entity:
JCMG.EntitasRedux.IEntity JCMG.EntitasRedux.IAERC

Public Member Functions

 Entity ()
 
override string ToString ()
 Returns a cached string to describe the entity with the following format: Entity_{creationIndex}(*{retainCount})({list of components}) More...
 
void Initialize (int creationIndex, int totalComponents, Stack< IComponent >[] componentPools, ContextInfo contextInfo=null, IAERC aerc=null)
 
void Reactivate (int creationIndex)
 
void AddComponent (int index, IComponent component)
 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 preferred way is to use the generated methods from the code generator. More...
 
void RemoveComponent (int index)
 Removes a component at the specified index. You can only remove a component at an index if it exists. The preferred way is to use the generated methods from the code generator. More...
 
void ReplaceComponent (int index, IComponent component)
 Replaces an existing component at the specified index or adds it if it doesn't exist yet. The preferred way is to use the generated methods from the code generator. More...
 
IComponent GetComponent (int index)
 Returns a component at the specified index. You can only get a component at an index if it exists. The preferred way is to use the generated methods from the code generator. More...
 
IComponent[] GetComponents ()
 Returns all added components. More...
 
int[] GetComponentIndices ()
 Returns all indices of added components. More...
 
bool HasComponent (int index)
 Determines whether this entity has a component at the specified index. More...
 
bool HasComponents (int[] indices)
 Determines whether this entity has components at all the specified indices. More...
 
bool HasAnyComponent (int[] indices)
 Determines whether this entity has a component at any of the specified indices. More...
 
void RemoveAllComponents ()
 Removes all components. More...
 
Stack< IComponentGetComponentPool (int index)
 Returns the componentPool for the specified component index. componentPools is set by the context 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. More...
 
IComponent CreateComponent (int index, Type type)
 Returns a new or reusable component from the componentPool for the specified component index. More...
 
CreateComponent< T > (int index)
 Returns a new or reusable component from the componentPool for the specified component index. More...
 
void Retain (object owner)
 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. More...
 
void Release (object owner)
 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. More...
 
void Destroy ()
 Dispatches OnDestroyEntity which will start the destroy process. More...
 
void InternalDestroy ()
 This method is used internally. Don't call it yourself. Use entity.Destroy(); More...
 
void RemoveAllOnEntityReleasedHandlers ()
 Do not call this method manually. This method is called by the context. More...
 

Public Attributes

int TotalComponents => _totalComponents
 The total amount of components an entity can possibly have. More...
 
int CreationIndex => _creationIndex
 Each entity has its own unique creationIndex which will be set by the context when you create the entity. More...
 
bool IsEnabled => _isEnabled
 The context manages the state of an entity. Active entities are enabled, destroyed entities are not. More...
 
Stack< IComponent >[] ComponentPools => _componentPools
 componentPools is set by the context 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. More...
 
ContextInfo ContextInfo => _contextInfo
 The contextInfo is set by the context which created the entity and contains information about the context. It's used to provide better error messages. More...
 
IAERC AERC => _aerc
 Automatic Entity Reference Counting (AERC) is used internally to prevent pooling retained entities. If you use retain manually you also have to release it manually at some point. More...
 
int RetainCount => _aerc.RetainCount
 Returns the number of objects that retain this entity. More...
 

Events

EntityComponentChanged OnComponentAdded
 Occurs when a component gets added. All event handlers will be removed when the entity gets destroyed by the context. More...
 
EntityComponentChanged OnComponentRemoved
 Occurs when a component gets removed. All event handlers will be removed when the entity gets destroyed by the context. More...
 
EntityComponentReplaced OnComponentReplaced
 Occurs when a component gets replaced. All event handlers will be removed when the entity gets destroyed by the context. More...
 
EntityEvent 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 context. More...
 
EntityEvent OnDestroyEntity
 Occurs when calling entity.Destroy(). All event handlers will be removed when the entity gets destroyed by the context. More...
 
- Events inherited from JCMG.EntitasRedux.IEntity
EntityComponentChanged OnComponentAdded
 
EntityComponentChanged OnComponentRemoved
 
EntityComponentReplaced OnComponentReplaced
 
EntityEvent OnEntityReleased
 
EntityEvent OnDestroyEntity
 

Additional Inherited Members

- Properties inherited from JCMG.EntitasRedux.IEntity
int TotalComponents [get]
 
int CreationIndex [get]
 
bool IsEnabled [get]
 
Stack< IComponent >[] ComponentPools [get]
 
ContextInfo ContextInfo [get]
 
IAERC AERC [get]
 
- Properties inherited from JCMG.EntitasRedux.IAERC
int RetainCount [get]
 

Detailed Description

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

Definition at line 37 of file Entity.cs.

Constructor & Destructor Documentation

◆ Entity()

JCMG.EntitasRedux.Entity.Entity ( )

Definition at line 56 of file Entity.cs.

Member Function Documentation

◆ AddComponent()

void JCMG.EntitasRedux.Entity.AddComponent ( int  index,
IComponent  component 
)

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 preferred way is to use the generated methods from the code generator.

Parameters
index
component

Implements JCMG.EntitasRedux.IEntity.

Definition at line 279 of file Entity.cs.

◆ CreateComponent()

IComponent JCMG.EntitasRedux.Entity.CreateComponent ( int  index,
Type  type 
)

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

Parameters
index
type
Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 542 of file Entity.cs.

◆ CreateComponent< T >()

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

Template Parameters
T
Parameters
index
Returns

Implements JCMG.EntitasRedux.IEntity.

Type Constraints
T :new() 

Definition at line 557 of file Entity.cs.

◆ Destroy()

void JCMG.EntitasRedux.Entity.Destroy ( )

Dispatches OnDestroyEntity which will start the destroy process.

Implements JCMG.EntitasRedux.IEntity.

Definition at line 610 of file Entity.cs.

◆ GetComponent()

IComponent JCMG.EntitasRedux.Entity.GetComponent ( int  index)

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

Parameters
index
Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 384 of file Entity.cs.

◆ GetComponentIndices()

int [] JCMG.EntitasRedux.Entity.GetComponentIndices ( )

Returns all indices of added components.

Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 430 of file Entity.cs.

◆ GetComponentPool()

Stack<IComponent> JCMG.EntitasRedux.Entity.GetComponentPool ( int  index)

Returns the componentPool for the specified component index. componentPools is set by the context 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.

Parameters
index
Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 523 of file Entity.cs.

◆ GetComponents()

IComponent [] JCMG.EntitasRedux.Entity.GetComponents ( )

Returns all added components.

Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 406 of file Entity.cs.

◆ HasAnyComponent()

bool JCMG.EntitasRedux.Entity.HasAnyComponent ( int[]  indices)

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

Parameters
indices
Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 485 of file Entity.cs.

◆ HasComponent()

bool JCMG.EntitasRedux.Entity.HasComponent ( int  index)

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

Parameters
index
Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 455 of file Entity.cs.

◆ HasComponents()

bool JCMG.EntitasRedux.Entity.HasComponents ( int[]  indices)

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

Parameters
indices
Returns

Implements JCMG.EntitasRedux.IEntity.

Definition at line 466 of file Entity.cs.

◆ Initialize()

void JCMG.EntitasRedux.Entity.Initialize ( int  creationIndex,
int  totalComponents,
Stack< IComponent >[]  componentPools,
ContextInfo  contextInfo = null,
IAERC  aerc = null 
)

Implements JCMG.EntitasRedux.IEntity.

Definition at line 251 of file Entity.cs.

◆ InternalDestroy()

void JCMG.EntitasRedux.Entity.InternalDestroy ( )

This method is used internally. Don't call it yourself. Use entity.Destroy();

Implements JCMG.EntitasRedux.IEntity.

Definition at line 624 of file Entity.cs.

◆ Reactivate()

void JCMG.EntitasRedux.Entity.Reactivate ( int  creationIndex)

Implements JCMG.EntitasRedux.IEntity.

Definition at line 264 of file Entity.cs.

◆ Release()

void JCMG.EntitasRedux.Entity.Release ( object  owner)

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.

Parameters
owner

Implements JCMG.EntitasRedux.IAERC.

Definition at line 594 of file Entity.cs.

◆ RemoveAllComponents()

void JCMG.EntitasRedux.Entity.RemoveAllComponents ( )

Removes all components.

Implements JCMG.EntitasRedux.IEntity.

Definition at line 501 of file Entity.cs.

◆ RemoveAllOnEntityReleasedHandlers()

void JCMG.EntitasRedux.Entity.RemoveAllOnEntityReleasedHandlers ( )

Do not call this method manually. This method is called by the context.

Implements JCMG.EntitasRedux.IEntity.

Definition at line 637 of file Entity.cs.

◆ RemoveComponent()

void JCMG.EntitasRedux.Entity.RemoveComponent ( int  index)

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

Parameters
index

Implements JCMG.EntitasRedux.IEntity.

Definition at line 318 of file Entity.cs.

◆ ReplaceComponent()

void JCMG.EntitasRedux.Entity.ReplaceComponent ( int  index,
IComponent  component 
)

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

Parameters
index
component

Implements JCMG.EntitasRedux.IEntity.

Definition at line 354 of file Entity.cs.

◆ Retain()

void JCMG.EntitasRedux.Entity.Retain ( object  owner)

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.

Parameters
owner

Implements JCMG.EntitasRedux.IAERC.

Definition at line 577 of file Entity.cs.

◆ ToString()

override string JCMG.EntitasRedux.Entity.ToString ( )

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

Returns

Definition at line 119 of file Entity.cs.

Member Data Documentation

◆ AERC

IAERC JCMG.EntitasRedux.Entity.AERC => _aerc

Automatic Entity Reference Counting (AERC) 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 249 of file Entity.cs.

◆ ComponentPools

Stack<IComponent> [] JCMG.EntitasRedux.Entity.ComponentPools => _componentPools

componentPools is set by the context 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 234 of file Entity.cs.

◆ ContextInfo

ContextInfo JCMG.EntitasRedux.Entity.ContextInfo => _contextInfo

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

Definition at line 241 of file Entity.cs.

◆ CreationIndex

int JCMG.EntitasRedux.Entity.CreationIndex => _creationIndex

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

Definition at line 217 of file Entity.cs.

◆ IsEnabled

bool JCMG.EntitasRedux.Entity.IsEnabled => _isEnabled

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

Definition at line 223 of file Entity.cs.

◆ RetainCount

int JCMG.EntitasRedux.Entity.RetainCount => _aerc.RetainCount

Returns the number of objects that retain this entity.

Definition at line 567 of file Entity.cs.

◆ TotalComponents

int JCMG.EntitasRedux.Entity.TotalComponents => _totalComponents

The total amount of components an entity can possibly have.

Definition at line 211 of file Entity.cs.

Event Documentation

◆ OnComponentAdded

EntityComponentChanged JCMG.EntitasRedux.Entity.OnComponentAdded

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

Definition at line 178 of file Entity.cs.

◆ OnComponentRemoved

EntityComponentChanged JCMG.EntitasRedux.Entity.OnComponentRemoved

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

Definition at line 185 of file Entity.cs.

◆ OnComponentReplaced

EntityComponentReplaced JCMG.EntitasRedux.Entity.OnComponentReplaced

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

Definition at line 192 of file Entity.cs.

◆ OnDestroyEntity

EntityEvent JCMG.EntitasRedux.Entity.OnDestroyEntity

Occurs when calling entity.Destroy(). All event handlers will be removed when the entity gets destroyed by the context.

Definition at line 206 of file Entity.cs.

◆ OnEntityReleased

EntityEvent JCMG.EntitasRedux.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 context.

Definition at line 199 of file Entity.cs.


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