Skip to content
Anthony Baynham edited this page May 29, 2016 · 3 revisions

What is an Entity?

An Entity is just a list of components and a "tag" (an identifier used to tell entities apart). Entities should never update or draw their components directly, this should be done through Systems.

Methods

IComponent AddComponent(IComponent component)

Checks if this already has "component". If it does, throws a ComponentAlreadyExistsException. Otherwise, add the component to "Components", and fire the ComponentAdded event (if it's also not null).

Returns the component you just added (¯_(ツ)_/¯)

void RemoveComponent(IComponent component)

Removes "component" if it isn't null and "this" contains the component.

T GetComponent< T >() where T : IComponent

Checks through Components for a component of type "T". If it doesn't have one, throw ComponentNotFoundException. Otherwise returns the first component of that type.

void MoveComponent(IComponent component, Entity destination)

Moves a component between this and "destination". If destination or the component are null, throw a ComponentNotFoundException. Otherwise add the component to the destination and remove it from "this".

bool HasComponent() where TComponent : IComponent

Checks if "this" contains a component of type "TComponent". If it does, return true. Otherwise, return false.

public void RemoveAllComponents()

Removes all components from "this".

void Reset()

Start afresh, calls RemoveAllComponents(), resets tag to an empty string and sets OwnerPool to null.

void AddComponents(params IComponent[] components)

Allows an infinite(?) number of components as parameters and adds them all at once to "this".

void AddComponents(IEnumerable components)

Adds an IEnumerable of components to an Entity all at once. Calls AddComponents(params IComponent[] components) anyway.

public void MoveTo(EntityPool pool)

Moves this Entity to another EntityPool (if it isn't null).

Entity CarbonCopy(string newTag)

Creates a "carbon copy" of this Entity with the tag of "newTag".

static Entity operator + (Entity entity, IComponent component)

Allows you to use a "+=" to add a component to "this". For example:

myEntity += new TransformComponent();