StateMachine

Namespace: Bang.StateMachines
Assembly: Bang.dll

public abstract class StateMachine

This is a basic state machine for an entity. It is sort-of anti-pattern of ECS at this point. This is a trade-off between adding content and using ECS at the core of the game.

⭐ Constructors

protected StateMachine()

⭐ Properties

Entity

protected Entity Entity;

Entity of the state machine. Initialized in StateMachine.Initialize(Bang.World,Bang.Entities.Entity).

Returns
Entity

Name

public string Name { get; private set; }

Name of the active state. Used for debug.

Returns
string

PersistStateOnSave

protected virtual bool PersistStateOnSave { get; }

Whether the state machine active state should be persisted on serialization.

Returns
bool

World

protected World World;

World of the state machine. Initialized in StateMachine.Initialize(Bang.World,Bang.Entities.Entity).

Returns
World

⭐ Methods

OnMessage(IMessage)

protected virtual void OnMessage(IMessage message)

Implemented by state machine implementations that want to listen to message notifications from outer systems.

Parameters
message IMessage

OnStart()

protected virtual void OnStart()

Initialize the state machine. Called before the first StateMachine.Tick(System.Single) call.

Transition(Func)

protected virtual void Transition(Func<TResult> routine)

Redirects the state machine to a new without doing a tick.

Parameters
routine Func<TResult>

GoTo(Func)

protected virtual Wait GoTo(Func<TResult> routine)

Redirects the state machine to a new .

Parameters
routine Func<TResult>

Returns
Wait

Reset()

protected void Reset()

This resets the current state of the state machine back to the beginning of that same state.

State(Func)

protected void State(Func<TResult> routine)

Set the current state of the state machine with .

Parameters
routine Func<TResult>

SwitchState(Func)

protected void SwitchState(Func<TResult> routine)

Redirects the state machine to a new without doing a tick.

Parameters
routine Func<TResult>

OnDestroyed()

public virtual void OnDestroyed()

Clean up right before the state machine gets cleaned up. Callers must call the base implementation.