StateMachine<TState> Class

Summary

A simple keyless Finite State Machine system.
Assembly
Animancer.dll
Namespace
Animancer.FSM
Interfaces
Base Types
  • Object
Derived Types
graph BT Type-->Base0["Object"] Type-.->Interface0["IStateMachine"] click Interface0 "/animancer/api/Animancer.FSM/IStateMachine" Type["StateMachine<TState>"] class Type type-node Derived0["StateMachine<TKey, TState>"]-->Type click Derived0 "/animancer/api/Animancer.FSM/StateMachine_2" Derived1["StateMachine<TState>.WithDefault"]-->Type click Derived1 "/animancer/api/Animancer.FSM/WithDefault"

Syntax

[HelpURL(StateExtensions.APIDocumentationURL + nameof(StateMachine<TState>) + "_1")]
[Serializable]
public class StateMachine<TState> : IStateMachine where TState : class, IState

Remarks

This class doesn't keep track of any states other than the currently active one. See Animancer.FSM.StateMachine`2 for a system that allows states to be pre-registered and accessed using a separate key.

See Animancer.FSM.StateMachine`1.InitializeAfterDeserialize if using this class in a serialized field.

Documentation: Finite State Machines

Attributes

Type Description
HelpURLAttribute
SerializableAttribute

Type Parameters

Name Description
TState

Constructors

Name Summary
StateMachine() Creates a new Animancer.FSM.StateMachine`1, leaving the Animancer.FSM.StateMachine`1.CurrentState null.
StateMachine(TState) Creates a new Animancer.FSM.StateMachine`1 and immediately enters the `state`.

Properties

Name Value Summary
AllowNullStates bool
[Assert-Only] Should the Animancer.FSM.StateMachine`1.CurrentState be allowed to be set to null? Default is false.
CurrentState TState
[UnityEngine.SerializeField] The currently active state.
GUILineCount int
[Editor-Only] The number of standard size lines that Animancer.FSM.StateMachine`1.DoGUI will use.
NextState TState
The Animancer.FSM.StateChange`1.NextState.
PreviousState TState
The Animancer.FSM.StateChange`1.PreviousState.

Methods

Name Value Summary
CanSetState(IList<TState>) TState
Returns the first of the `states` which can currently be entered.
CanSetState(TState) bool
Is it currently possible to enter the specified `state`?
DoGUI() void
[Editor-Only] Draws GUI fields to display the status of this state machine.
DoGUI(Rect) void
[Editor-Only] Draws GUI fields to display the status of this state machine in the given `area`.
ForceSetState(TState) void
Calls Animancer.FSM.IState.OnExitState on the Animancer.FSM.StateMachine`1.CurrentState then changes it to the specified `state` and calls Animancer.FSM.IState.OnEnterState on it.
InitializeAfterDeserialize() void
Call this after deserializing to properly initialize the Animancer.FSM.StateMachine`1.CurrentState.
SetAllowNullStates(bool) void
[Assert-Conditional] Sets Animancer.FSM.StateMachine`1.AllowNullStates.
ToString() string
Returns a string describing the type of this state machine and its Animancer.FSM.StateMachine`1.CurrentState.
TryResetState(IList<TState>) bool
Attempts to enter any of the specified `states` and returns true if successful.
TryResetState(TState) bool
Attempts to enter the specified `state` and returns true if successful.
TrySetState(IList<TState>) bool
Attempts to enter any of the specified `states` and returns true if successful.
TrySetState(TState) bool
Attempts to enter the specified `state` and returns true if successful.