Twoorb Plugins  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties
Twoorb.Utilities.StateMachine< T > Class Template Reference

A state machine utility class. Use AddState to Add the states and callbacks and use TriggerState to use them. More...

Public Member Functions

void AddState (T stateType, ActionEventHandler stateEnterCallback=null, ActionEventHandler stateUpdateCallback=null, ActionEventHandler stateLeaveCallback=null)
 Adds and registers a state to the state machine. When the state is triggered (with TriggerState()), the appropriate callbacks will be invoked. More...
 
bool TriggerState (T stateType)
 Triggers a state in the state machine. Will end the current state if there is an active one. More...
 
bool TriggerPreviousState ()
 Triggers the previous state if the statemachine has one. More...
 
bool TriggerState (T stateType, float delay)
 Triggers a state with a delay More...
 
void Update ()
 Updates the state machine. Call this if you have any 'Update' - states More...
 
bool WasPreviousState (T stateType)
 Checks if the specified state was the previous one. More...
 

Properties

float TimeInState [get]
 Returns the time spent in the current state. Requires Update() to be called. More...
 
bool HasCurrentState [get]
 Returns if the state machine currently has a state. More...
 
CurrentStateType [get]
 Returns the current state type More...
 
bool HasPreviousState [get]
 Returns if the state machine has a previous state More...
 

Detailed Description

A state machine utility class. Use AddState to Add the states and callbacks and use TriggerState to use them.

Template Parameters
TThe type of the state. Preferably an enum

Member Function Documentation

void Twoorb.Utilities.StateMachine< T >.AddState ( stateType,
ActionEventHandler  stateEnterCallback = null,
ActionEventHandler  stateUpdateCallback = null,
ActionEventHandler  stateLeaveCallback = null 
)

Adds and registers a state to the state machine. When the state is triggered (with TriggerState()), the appropriate callbacks will be invoked.

Parameters
stateTypeThe state to register
stateEnterCallbackCallback when the statemachine enters the state
stateUpdateCallbackCallback when the statemachine is in the state. (Requires Update() to be called)
stateLeaveCallbackCallback when the statemachine is leaving the state
bool Twoorb.Utilities.StateMachine< T >.TriggerPreviousState ( )

Triggers the previous state if the statemachine has one.

Returns
Returns if the operation was successful
bool Twoorb.Utilities.StateMachine< T >.TriggerState ( stateType)

Triggers a state in the state machine. Will end the current state if there is an active one.

Parameters
stateTypeThe state to trigger
Returns
Returns is the state triggered successfully
bool Twoorb.Utilities.StateMachine< T >.TriggerState ( stateType,
float  delay 
)

Triggers a state with a delay

Parameters
stateTypeThe state to trigger
delayHow long until the state should be triggered. In seconds.
Returns
Returns if the operation was successful
void Twoorb.Utilities.StateMachine< T >.Update ( )

Updates the state machine. Call this if you have any 'Update' - states

bool Twoorb.Utilities.StateMachine< T >.WasPreviousState ( stateType)

Checks if the specified state was the previous one.

Parameters
stateTypeThe state to check
Returns
Returns if the state was the previous active one.

Property Documentation

T Twoorb.Utilities.StateMachine< T >.CurrentStateType
get

Returns the current state type

bool Twoorb.Utilities.StateMachine< T >.HasCurrentState
get

Returns if the state machine currently has a state.

bool Twoorb.Utilities.StateMachine< T >.HasPreviousState
get

Returns if the state machine has a previous state

float Twoorb.Utilities.StateMachine< T >.TimeInState
get

Returns the time spent in the current state. Requires Update() to be called.


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