JUtils
A unity utilities library
JUtils.StateMachine Class Referenceabstract

A mono behaviour state-machine that can also be used as a state More...

Inheritance diagram for JUtils.StateMachine:
Collaboration diagram for JUtils.StateMachine:

Classes

struct  QueueEntry
 Representation of the state and its data in the queue More...
 

Public Member Functions

void GoToState ([NotNull] State state, [CanBeNull] StateData data)
 Queues the current given state, then goes to it More...
 
void GoToState< T > ([CanBeNull] StateData data)
 Clears the StateQueue and goes to the given state More...
 
void AddToQueue ([NotNull] State state, [CanBeNull] StateData data, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T > ([CanBeNull] StateData data, bool queueFirst=false)
 Adds a new state to the queue More...
 
void ClearQueue ()
 Clears all states in the queue More...
 
void ContinueQueue ()
 Deactivate the current state and go to the next one More...
 
FindState< T > ()
 Find a state within the child objects of this state-machine, if _autoCreateStates is enabled, it will automatically instantiate the state More...
 
bool TryFindState< T > (out T state)
 Try finding a state within the child objects of this state-machine, if _autoCreateStates is enabled, it will automatically instantiate that state More...
 
void Activate ([CanBeNull] StateData data=null)
 Activates the state machine More...
 
new void Deactivate ()
 Continues the queue in the state machine, or deactivates the state if it is the root state machine More...
 
void GoToState (State state)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T, T1 > (T state, T1 arg1)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T, T1, T2 > (T state, T1 arg1, T2 arg2)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T, T1, T2, T3 > (T state, T1 arg1, T2 arg2, T3 arg3)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T > ()
 Adds a new state to the queue More...
 
void GoToState< T, T1 > (T1 arg1)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T, T1, T2 > (T1 arg1, T2 arg2)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T, T1, T2, T3 > (T1 arg1, T2 arg2, T3 arg3)
 Clears the StateQueue and goes to the given state More...
 
void GoToState< T, T1, T2, T3 > (StateRef< T > stateRef, T1 arg1, T2 arg2, T3 arg3)
 Adds a new state to the queue More...
 
void GoToState< T, T1, T2 > (StateRef< T > stateRef, T1 arg1, T2 arg2)
 Adds a new state to the queue More...
 
void GoToState< T, T1 > (StateRef< T > stateRef, T1 arg1)
 Adds a new state to the queue More...
 
void GoToState< T > (StateRef< T > stateRef)
 Adds a new state to the queue More...
 
void AddToQueue< T > (T state, bool queueFist=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1 > (T state, T1 arg1, bool queueFist=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1, T2 > (T state, T1 arg1, T2 arg2, bool queueFist=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1, T2, T3 > (T state, T1 arg1, T2 arg2, T3 arg3, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T > (bool queueFist=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1 > (T1 arg1, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1, T2 > (T1 arg1, T2 arg2, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1, T2, T3 > (T1 arg1, T2 arg2, T3 arg3, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1, T2, T3 > (StateRef< T > stateRef, T1 arg1, T2 arg2, T3 arg3, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1, T2 > (StateRef< T > stateRef, T1 arg1, T2 arg2, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T, T1 > (StateRef< T > stateRef, T1 arg1, bool queueFirst=false)
 Adds a new state to the queue More...
 
void AddToQueue< T > (StateRef< T > stateRef, bool queueFirst=false)
 Adds a new state to the queue More...
 

Protected Member Functions

abstract void OnNoState ()
 Gets called when there is no next state in the queue More...
 
override void Awake ()
 
virtual void Start ()
 
virtual void Reset ()
 
virtual void OnValidate ()
 
- Protected Member Functions inherited from JUtils.State< T1, T2, T3 >
void Deactivate ()
 Deactivate this state and make the state-machine continue its queue More...
 
abstract void OnActivate ()
 Gets called when the state activates More...
 
abstract void OnDeactivate ()
 Gets called when the sate deactivates More...
 
StateRef< T > Ref< T > ()
 Used for making typed argument adding to states prettier More...
 
virtual void ActiveUpdate ()
 Only runs the Update() function when the state is active More...
 
virtual void Update ()
 
override void OnActivate ()
 
abstract void OnActivate (T param)
 
override void OnActivate ()
 
abstract void OnActivate (T1 param1, T2 param2)
 
override void OnActivate ()
 
abstract void OnActivate (T1 param1, T2 param2, T3 param3)
 

Protected Attributes

State currentState
 
List< QueueEntrystateQueue = new()
 

Properties

bool hasActiveState [get]
 
bool isQueueFilled [get]
 
bool isQueueEmpty [get]
 
new StateMachine stateMachine [get]
 
- Properties inherited from JUtils.State< T1, T2, T3 >
bool isActive [get]
 
bool isActivating [get]
 Is set to true while the state is activating More...
 
bool isDeactivating [get]
 Is set to true while the state is deactivating More...
 
StateMachine stateMachine [get, set]
 The reference of this state's state machine More...
 
float timeInState [get]
 Get the amount of seconds that this state is active. Returns 0 if the state is not active More...
 
float unscaledTimeInState [get]
 Get the amount of unscaled seconds that this state is active. Returns 0 if the state is not active More...
 
StateData stateData [get]
 

Events

Action< StateonStateChanged
 
- Events inherited from JUtils.State< T1, T2, T3 >
Action< StateonStateActivate
 
Action< StateonStateDeactivate
 

Detailed Description

A mono behaviour state-machine that can also be used as a state

Member Function Documentation

◆ Activate()

void JUtils.StateMachine.Activate ( [CanBeNull] StateData  data = null)
inline

Activates the state machine

References JUtils.State< T1, T2, T3 >.isActive.

◆ AddToQueue()

void JUtils.StateMachine.AddToQueue ( [NotNull] State  state,
[CanBeNull] StateData  data,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Here is the caller graph for this function:

◆ AddToQueue< T >() [1/4]

void JUtils.StateMachine.AddToQueue< T > ( [CanBeNull] StateData  data,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 

References JUtils.StateMachine.AddToQueue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddToQueue< T >() [2/4]

void JUtils.StateMachine.AddToQueue< T > ( bool  queueFist = false)
inline

Adds a new state to the queue

Type Constraints
T :State 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T >() [3/4]

void JUtils.StateMachine.AddToQueue< T > ( StateRef< T >  stateRef,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T >() [4/4]

void JUtils.StateMachine.AddToQueue< T > ( state,
bool  queueFist = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 

References JUtils.StateMachine.AddToQueue().

Here is the call graph for this function:

◆ AddToQueue< T, T1 >() [1/3]

void JUtils.StateMachine.AddToQueue< T, T1 > ( StateRef< T >  stateRef,
T1  arg1,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State<T1> 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T, T1 >() [2/3]

void JUtils.StateMachine.AddToQueue< T, T1 > ( state,
T1  arg1,
bool  queueFist = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State<T1> 

References JUtils.StateMachine.AddToQueue().

Here is the call graph for this function:

◆ AddToQueue< T, T1 >() [3/3]

void JUtils.StateMachine.AddToQueue< T, T1 > ( T1  arg1,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State<T1> 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T, T1, T2 >() [1/3]

void JUtils.StateMachine.AddToQueue< T, T1, T2 > ( StateRef< T >  stateRef,
T1  arg1,
T2  arg2,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T, T1, T2 >() [2/3]

void JUtils.StateMachine.AddToQueue< T, T1, T2 > ( state,
T1  arg1,
T2  arg2,
bool  queueFist = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 

References JUtils.StateMachine.AddToQueue().

Here is the call graph for this function:

◆ AddToQueue< T, T1, T2 >() [3/3]

void JUtils.StateMachine.AddToQueue< T, T1, T2 > ( T1  arg1,
T2  arg2,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T, T1, T2, T3 >() [1/3]

void JUtils.StateMachine.AddToQueue< T, T1, T2, T3 > ( StateRef< T >  stateRef,
T1  arg1,
T2  arg2,
T3  arg3,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 
T :T3 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ AddToQueue< T, T1, T2, T3 >() [2/3]

void JUtils.StateMachine.AddToQueue< T, T1, T2, T3 > ( state,
T1  arg1,
T2  arg2,
T3  arg3,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 
T :T3 

References JUtils.StateMachine.AddToQueue().

Here is the call graph for this function:

◆ AddToQueue< T, T1, T2, T3 >() [3/3]

void JUtils.StateMachine.AddToQueue< T, T1, T2, T3 > ( T1  arg1,
T2  arg2,
T3  arg3,
bool  queueFirst = false 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 
T :T3 

References JUtils.StateMachine.AddToQueue< T >().

Here is the call graph for this function:

◆ Awake()

override void JUtils.StateMachine.Awake ( )
inlineprotectedvirtual

Reimplemented from JUtils.State< T1, T2, T3 >.

◆ ClearQueue()

void JUtils.StateMachine.ClearQueue ( )
inline

Clears all states in the queue

References JUtils.StateMachine.stateQueue.

◆ ContinueQueue()

void JUtils.StateMachine.ContinueQueue ( )
inline

◆ Deactivate()

new void JUtils.StateMachine.Deactivate ( )
inline

Continues the queue in the state machine, or deactivates the state if it is the root state machine

References JUtils.State< T1, T2, T3 >.isActive, and JUtils.StateMachine.stateMachine.

◆ FindState< T >()

T JUtils.StateMachine.FindState< T > ( )
inline

Find a state within the child objects of this state-machine, if _autoCreateStates is enabled, it will automatically instantiate the state

Type Constraints
T :State 

◆ GoToState() [1/2]

void JUtils.StateMachine.GoToState ( [NotNull] State  state,
[CanBeNull] StateData  data 
)
inline

Queues the current given state, then goes to it

References JUtils.StateMachine.ContinueQueue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GoToState() [2/2]

void JUtils.StateMachine.GoToState ( State  state)
inline

Clears the StateQueue and goes to the given state

References JUtils.StateMachine.GoToState().

Here is the call graph for this function:

◆ GoToState< T >() [1/3]

void JUtils.StateMachine.GoToState< T > ( )
inline

Adds a new state to the queue

Type Constraints
T :State 
Here is the caller graph for this function:

◆ GoToState< T >() [2/3]

void JUtils.StateMachine.GoToState< T > ( [CanBeNull] StateData  data)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State 

References JUtils.StateMachine.GoToState().

Here is the call graph for this function:

◆ GoToState< T >() [3/3]

void JUtils.StateMachine.GoToState< T > ( StateRef< T >  stateRef)
inline

Adds a new state to the queue

Type Constraints
T :State 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ GoToState< T, T1 >() [1/3]

void JUtils.StateMachine.GoToState< T, T1 > ( StateRef< T >  stateRef,
T1  arg1 
)
inline

Adds a new state to the queue

Type Constraints
T :State<T1> 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ GoToState< T, T1 >() [2/3]

void JUtils.StateMachine.GoToState< T, T1 > ( state,
T1  arg1 
)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State<T1> 

References JUtils.StateMachine.GoToState().

Here is the call graph for this function:

◆ GoToState< T, T1 >() [3/3]

void JUtils.StateMachine.GoToState< T, T1 > ( T1  arg1)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State<T1> 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ GoToState< T, T1, T2 >() [1/3]

void JUtils.StateMachine.GoToState< T, T1, T2 > ( StateRef< T >  stateRef,
T1  arg1,
T2  arg2 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ GoToState< T, T1, T2 >() [2/3]

void JUtils.StateMachine.GoToState< T, T1, T2 > ( state,
T1  arg1,
T2  arg2 
)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State 
T :T1 
T :T2 

References JUtils.StateMachine.GoToState().

Here is the call graph for this function:

◆ GoToState< T, T1, T2 >() [3/3]

void JUtils.StateMachine.GoToState< T, T1, T2 > ( T1  arg1,
T2  arg2 
)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State 
T :T1 
T :T2 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ GoToState< T, T1, T2, T3 >() [1/3]

void JUtils.StateMachine.GoToState< T, T1, T2, T3 > ( StateRef< T >  stateRef,
T1  arg1,
T2  arg2,
T3  arg3 
)
inline

Adds a new state to the queue

Type Constraints
T :State 
T :T1 
T :T2 
T :T3 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ GoToState< T, T1, T2, T3 >() [2/3]

void JUtils.StateMachine.GoToState< T, T1, T2, T3 > ( state,
T1  arg1,
T2  arg2,
T3  arg3 
)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State 
T :T1 
T :T2 
T :T3 

References JUtils.StateMachine.GoToState().

Here is the call graph for this function:

◆ GoToState< T, T1, T2, T3 >() [3/3]

void JUtils.StateMachine.GoToState< T, T1, T2, T3 > ( T1  arg1,
T2  arg2,
T3  arg3 
)
inline

Clears the StateQueue and goes to the given state

Type Constraints
T :State 
T :T1 
T :T2 
T :T3 

References JUtils.StateMachine.GoToState< T >().

Here is the call graph for this function:

◆ OnNoState()

abstract void JUtils.StateMachine.OnNoState ( )
protectedpure virtual

Gets called when there is no next state in the queue

Here is the caller graph for this function:

◆ OnValidate()

virtual void JUtils.StateMachine.OnValidate ( )
inlineprotectedvirtual

◆ Reset()

virtual void JUtils.StateMachine.Reset ( )
inlineprotectedvirtual

◆ Start()

virtual void JUtils.StateMachine.Start ( )
inlineprotectedvirtual

◆ TryFindState< T >()

bool JUtils.StateMachine.TryFindState< T > ( out T  state)
inline

Try finding a state within the child objects of this state-machine, if _autoCreateStates is enabled, it will automatically instantiate that state

Type Constraints
T :State 

Member Data Documentation

◆ currentState

State JUtils.StateMachine.currentState
protected

◆ stateQueue

List<QueueEntry> JUtils.StateMachine.stateQueue = new()
protected

Property Documentation

◆ hasActiveState

bool JUtils.StateMachine.hasActiveState
get

◆ isQueueEmpty

bool JUtils.StateMachine.isQueueEmpty
get

◆ isQueueFilled

bool JUtils.StateMachine.isQueueFilled
get

◆ stateMachine

new StateMachine JUtils.StateMachine.stateMachine
get

Event Documentation

◆ onStateChanged

Action<State> JUtils.StateMachine.onStateChanged

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