Entitas  1.13.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Entitas.Context< TEntity > Class Template Reference
Inheritance diagram for Entitas.Context< TEntity >:
Entitas.IContext< TEntity >

Public Member Functions

 Context (int totalComponents, Func< TEntity > entityFactory)
 
 Context (int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func< IEntity, IAERC > aercFactory, Func< TEntity > entityFactory)
 
TEntity CreateEntity ()
 
void DestroyAllEntities ()
 
bool HasEntity (TEntity entity)
 Determines whether the context has the specified entity.
 
TEntity [] GetEntities ()
 Returns all entities which are currently in the context.
 
IGroup< TEntity > GetGroup (IMatcher< TEntity > matcher)
 
void AddEntityIndex (IEntityIndex entityIndex)
 
IEntityIndex GetEntityIndex (string name)
 Gets the IEntityIndex for the specified name.
 
void ResetCreationIndex ()
 Resets the creationIndex back to 0.
 
void ClearComponentPool (int index)
 Clears the componentPool at the specified index.
 
void ClearComponentPools ()
 Clears all componentPools.
 
void Reset ()
 
void RemoveAllEventHandlers ()
 
override string ToString ()
 

Properties

int totalComponents [get]
 
Stack< IComponent > [] componentPools [get]
 
ContextInfo contextInfo [get]
 
int count [get]
 Returns the number of entities in the context.
 
int reusableEntitiesCount [get]
 
int retainedEntitiesCount [get]
 

Events

ContextEntityChanged OnEntityCreated
 Occurs when an entity gets created.
 
ContextEntityChanged OnEntityWillBeDestroyed
 Occurs when an entity will be destroyed.
 
ContextEntityChanged OnEntityDestroyed
 Occurs when an entity got destroyed.
 
ContextGroupChanged OnGroupCreated
 Occurs when a group gets created for the first time.
 

Detailed Description

A context manages the lifecycle of entities and groups. You can create and destroy entities and get groups of entities. The prefered way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Type Constraints
TEntity :class 
TEntity :IEntity 

Definition at line 12 of file Context.cs.

Constructor & Destructor Documentation

◆ Context() [1/2]

Entitas.Context< TEntity >.Context ( int  totalComponents,
Func< TEntity >  entityFactory 
)
inline

The prefered way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Definition at line 82 of file Context.cs.

◆ Context() [2/2]

Entitas.Context< TEntity >.Context ( int  totalComponents,
int  startCreationIndex,
ContextInfo  contextInfo,
Func< IEntity, IAERC aercFactory,
Func< TEntity >  entityFactory 
)
inline

The prefered way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Definition at line 87 of file Context.cs.

Member Function Documentation

◆ AddEntityIndex()

void Entitas.Context< TEntity >.AddEntityIndex ( IEntityIndex  entityIndex)
inline

Adds the IEntityIndex for the specified name. There can only be one IEntityIndex per name.

Definition at line 221 of file Context.cs.

◆ CreateEntity()

TEntity Entitas.Context< TEntity >.CreateEntity ( )
inline

Creates a new entity or gets a reusable entity from the internal ObjectPool for entities.

Definition at line 130 of file Context.cs.

◆ DestroyAllEntities()

void Entitas.Context< TEntity >.DestroyAllEntities ( )
inline

Destroys all entities in the context. Throws an exception if there are still retained entities.

Definition at line 160 of file Context.cs.

◆ GetGroup()

IGroup<TEntity> Entitas.Context< TEntity >.GetGroup ( IMatcher< TEntity >  matcher)
inline

Returns a group for the specified matcher. Calling context.GetGroup(matcher) with the same matcher will always return the same instance of the group.

Definition at line 191 of file Context.cs.

◆ RemoveAllEventHandlers()

void Entitas.Context< TEntity >.RemoveAllEventHandlers ( )
inline

Removes all event handlers OnEntityCreated, OnEntityWillBeDestroyed, OnEntityDestroyed and OnGroupCreated

Definition at line 269 of file Context.cs.

◆ Reset()

void Entitas.Context< TEntity >.Reset ( )
inline

Resets the context (destroys all entities and resets creationIndex back to 0).

Definition at line 261 of file Context.cs.

Property Documentation

◆ componentPools

Stack<IComponent> [] Entitas.Context< TEntity >.componentPools
get

Returns all componentPools. componentPools 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 36 of file Context.cs.

◆ contextInfo

ContextInfo Entitas.Context< TEntity >.contextInfo
get

The contextInfo contains information about the context. It's used to provide better error messages.

Definition at line 40 of file Context.cs.

◆ retainedEntitiesCount

int Entitas.Context< TEntity >.retainedEntitiesCount
get

Returns the number of entities that are currently retained by other objects (e.g. Group, Collector, ReactiveSystem).

Definition at line 51 of file Context.cs.

◆ reusableEntitiesCount

int Entitas.Context< TEntity >.reusableEntitiesCount
get

Returns the number of entities in the internal ObjectPool for entities which can be reused.

Definition at line 47 of file Context.cs.

◆ totalComponents

int Entitas.Context< TEntity >.totalComponents
get

The total amount of components an entity can possibly have. This value is generated by the code generator, e.g ComponentLookup.TotalComponents.

Definition at line 29 of file Context.cs.


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