Class Entity
Represents a game entity that typically aggregates multiple EntityComponent instances. For more information about entities, see Adding entities and Managing entities.
[ContentSerializer(typeof(Entity.EntityContentSerializer))]
[DataSerializer(typeof(Entity.EntitySerializer))]
[DataStyle(DataStyle.Normal)]
[DataContract("Entity")]
public sealed class Entity : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IEnumerable<EntityComponent>, IEnumerable, IIdentifiable
- Inheritance
-
Entity
- Implements
- Inherited Members
- Extension Methods
Constructors
Entity()
Create a new Entity instance.
public Entity()
Entity(string)
Create a new Entity instance having the provided name.
public Entity(string name)
Parameters
name
stringThe name to give to the entity
Entity(string, Vector3, Quaternion?, Vector3?)
Create a new Entity instance having the provided name, initial position, rotation and scale.
public Entity(string name = null, Vector3 position = default, Quaternion? rotation = null, Vector3? scale = null)
Parameters
name
stringThe name to give to the entity
position
Vector3The initial position of the entity
rotation
Quaternion?The initial rotation of the entity
scale
Vector3?The initial scale of the entity
Properties
Components
The components stored in this entity.
[DataMember(100, DataMemberMode.Content)]
public EntityComponentCollection Components { get; }
Property Value
EntityManager
The entity manager which processes this entity.
public EntityManager EntityManager { get; }
Property Value
Id
Gets the id of this instance
[DataMember(-10)]
[Display(null, null, Browsable = false)]
public Guid Id { get; set; }
Property Value
Name
Gets or sets the name of this component.
[DataMember(0)]
public override string Name { get; set; }
Property Value
- string
The name.
Scene
The scene this entity is in.
Setting this to null will remove the entity from the scene and detach it from its parent if it has one.
public Scene Scene { get; set; }
Property Value
Transform
Gets or sets the Transform associated to this entity. Added for convenience over usual Get/Set method.
public TransformComponent Transform { get; }
Property Value
Methods
Add(EntityComponent)
Adds the specified component to the entity.
public void Add(EntityComponent component)
Parameters
component
EntityComponentThe component to add.
Exceptions
- ArgumentNullException
Thrown if the component is null.
GetAll<T>()
Gets all components of the specified type.
public IEnumerable<T> GetAll<T>() where T : EntityComponent
Returns
- IEnumerable<T>
The component or null if does no exist
Type Parameters
T
Type of the component
GetEnumerator()
Gets the enumerator of EntityComponent
public FastCollection<EntityComponent>.Enumerator GetEnumerator()
Returns
GetOrCreate<T>()
Gets or create a component with the specified key.
public T GetOrCreate<T>() where T : EntityComponent, new()
Returns
- T
A new or existing instance of {T}
Type Parameters
T
Type of the entity component
Get<T>()
Gets the first component of the specified type.
public T Get<T>() where T : EntityComponent
Returns
- T
The component or null if does no exist
Type Parameters
T
Type of the component
Get<T>(int)
Gets the index'th component of the specified type. See remarks.
public T Get<T>(int index) where T : EntityComponent
Parameters
index
intThe index'th component to select.
Returns
- T
The component or null if does no exist
Type Parameters
T
Type of the component
Remarks
- If index > 0, it will take the index'th component of the specified
T
. - An index == 0 is equivalent to calling Get<T>()
- if index < 0, it will start from the end of the list to the beginning. A value of -1 means the first last component.
Remove(EntityComponent)
Removes the specified component.
public void Remove(EntityComponent component)
Parameters
component
EntityComponent
RemoveAll<T>()
Removes all components of the specified type or derived type.
public void RemoveAll<T>() where T : EntityComponent
Type Parameters
T
Type of the component
Remove<T>()
Removes the first component of the specified type or derived type.
public void Remove<T>() where T : EntityComponent
Type Parameters
T
Type of the component
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.