Highroad Engine v1.3
Public Member Functions | Public Attributes | Properties | List of all members
MoreMountains.Tools.MMStateMachine< T > Class Template Reference

StateMachine manager, designed with simplicity in mind (as simple as a state machine can be anyway). To use it, you need an enum. For example : public enum CharacterConditions { Normal, ControlledMovement, Frozen, Paused, Dead } Declare it like so : public StateMachine<CharacterConditions> ConditionStateMachine; Initialize it like that : ConditionStateMachine = new StateMachine<CharacterConditions>(); Then from anywhere, all you need to do is update its state when needed, like that for example : ConditionStateMachine.ChangeState(CharacterConditions.Dead); The state machine will store for you its current and previous state, accessible at all times, and will also optionnally trigger events on enter/exit of these states. More...

Inheritance diagram for MoreMountains.Tools.MMStateMachine< T >:
MoreMountains.Tools.MMIStateMachine

Public Member Functions

delegate void OnStateChangeDelegate ()
 
 MMStateMachine (GameObject target, bool triggerEvents)
 Creates a new StateMachine, with a targetName (used for events, usually use GetInstanceID()), and whether you want to use events with it or not More...
 
virtual void ChangeState (T newState)
 Changes the current movement state to the one specified in the parameters, and triggers exit and enter events if needed More...
 
virtual void RestorePreviousState ()
 Returns the character to the state it was in before its current state More...
 

Public Attributes

GameObject Target
 the name of the target gameobject More...
 
OnStateChangeDelegate OnStateChange
 

Properties

bool TriggerEvents [getset]
 
CurrentState [getprotected set]
 the current character's movement state More...
 
PreviousState [getprotected set]
 the character's movement state before entering the current one More...
 
- Properties inherited from MoreMountains.Tools.MMIStateMachine
bool TriggerEvents [getset]
 

Detailed Description

StateMachine manager, designed with simplicity in mind (as simple as a state machine can be anyway). To use it, you need an enum. For example : public enum CharacterConditions { Normal, ControlledMovement, Frozen, Paused, Dead } Declare it like so : public StateMachine<CharacterConditions> ConditionStateMachine; Initialize it like that : ConditionStateMachine = new StateMachine<CharacterConditions>(); Then from anywhere, all you need to do is update its state when needed, like that for example : ConditionStateMachine.ChangeState(CharacterConditions.Dead); The state machine will store for you its current and previous state, accessible at all times, and will also optionnally trigger events on enter/exit of these states.

Type Constraints
T :struct 
T :IComparable 
T :IConvertible 
T :IFormattable 

Constructor & Destructor Documentation

◆ MMStateMachine()

MoreMountains.Tools.MMStateMachine< T >.MMStateMachine ( GameObject  target,
bool  triggerEvents 
)

Creates a new StateMachine, with a targetName (used for events, usually use GetInstanceID()), and whether you want to use events with it or not

Parameters
targetNameTarget name.
triggerEventsIf set to true trigger events.

Member Function Documentation

◆ ChangeState()

virtual void MoreMountains.Tools.MMStateMachine< T >.ChangeState ( newState)
virtual

Changes the current movement state to the one specified in the parameters, and triggers exit and enter events if needed

Parameters
newStateNew state.

◆ OnStateChangeDelegate()

delegate void MoreMountains.Tools.MMStateMachine< T >.OnStateChangeDelegate ( )

◆ RestorePreviousState()

virtual void MoreMountains.Tools.MMStateMachine< T >.RestorePreviousState ( )
virtual

Returns the character to the state it was in before its current state

Member Data Documentation

◆ OnStateChange

an event you can listen to to listen locally to changes on that state machine to listen to them, from any class : void OnEnable() { yourReferenceToTheStateMachine.OnStateChange += OnStateChange; } void OnDisable() { yourReferenceToTheStateMachine.OnStateChange -= OnStateChange; } void OnStateChange() { // Do something }

◆ Target

GameObject MoreMountains.Tools.MMStateMachine< T >.Target

the name of the target gameobject

Property Documentation

◆ CurrentState

T MoreMountains.Tools.MMStateMachine< T >.CurrentState
getprotected set

the current character's movement state

◆ PreviousState

T MoreMountains.Tools.MMStateMachine< T >.PreviousState
getprotected set

the character's movement state before entering the current one

◆ TriggerEvents

bool MoreMountains.Tools.MMStateMachine< T >.TriggerEvents
getset

If you set TriggerEvents to true, the state machine will trigger events when entering and exiting a state. Additionnally, it has options to trigger events for the current state on FixedUpdate, LateUpdate, but also on Update (separated in EarlyUpdate, Update and EndOfUpdate, triggered in this order at Update() To listen to these events, from any class, in its Start() method (or wherever you prefer), use MMEventManager.StartListening(gameObject.GetInstanceID().ToString()+"XXXEnter",OnXXXEnter); where XXX is the name of the state you're listening to, and OnXXXEnter is the method you want to call when that event is triggered. MMEventManager.StartListening(gameObject.GetInstanceID().ToString()+"CrouchingEarlyUpdate",OnCrouchingEarlyUpdate); for example will listen to the Early Update event of the Crouching state, and will trigger the OnCrouchingEarlyUpdate() method.


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