Summary
A simple Finite State Machine system that registers each state with a particular key.
- Assembly
- Animancer
.dll - Namespace
- Animancer
.FSM - Interfaces
-
- IStateMachine
- IKeyedStateMachine
<TKey> - IDictionary
<TKey, TState>
- Base Types
-
- Object
- StateMachine
<TState>
- Derived Types
graph BT
Type-->Base0["StateMachine<TState>"]
Base0-->Base1["Object"]
Type-.->Interface0["IStateMachine"]
click Interface0 "/animancer-v7-4/api/Animancer.FSM/IStateMachine"
Type-.->Interface1["IKeyedStateMachine<TKey>"]
Type-.->Interface2["IDictionary<TKey, TState>"]
Type["StateMachine<TKey, TState>"]
class Type type-node
Derived0["StateMachine<TKey, TState>.WithDefault"]-->Type
click Derived0 "/animancer-v7-4/api/Animancer.FSM/WithDefault"
Syntax
[HelpURL(StateExtensions.APIDocumentationURL + nameof(StateMachine<TState>) + "_2")]
[Serializable]
public class StateMachine<TKey, TState> : StateMachine<TState>, IStateMachine,
IKeyedStateMachine<TKey>, IDictionary<TKey, TState>
where TState : class, IState
Remarks
This class allows states to be registered with a particular key upfront and then accessed later using that key.
See
Animancer.FSM.StateMachine`1
for a system that does not bother keeping track of any states other than
the active one.
See Animancer.FSM.StateMachine`2.InitializeAfterDeserialize
if using this class in a serialized field.
Documentation: Keyed State Machines
Attributes
Type | Description |
---|---|
HelpURLAttribute | |
Serializable |
Type Parameters
Name | Description |
---|---|
TKey | |
TState |
Constructors
Name | Summary |
---|---|
StateMachine |
Creates a new Animancer.FSM.StateMachine`2 with a new Animancer.FSM.StateMachine`2.Dictionary , leaving the
CurrentState null.
|
StateMachine |
Creates a new Animancer.FSM.StateMachine`2 which uses the specified `dictionary`, leaving the
CurrentState null.
|
StateMachine |
Constructs a new Animancer.FSM.StateMachine`2 which uses the specified `dictionary` and
immediately uses the `defaultKey` to enter the `defaultState`.
|
StateMachine |
Constructs a new Animancer.FSM.StateMachine`2 with a new Animancer.FSM.StateMachine`2.Dictionary and
immediately uses the `defaultKey` to enter the `defaultState`.
|
Properties
Name | Value | Summary |
---|---|---|
Count | int |
Gets the number of states contained in the
Animancer.FSM.StateMachine`2.Dictionary . |
CurrentKey | TKey |
The key which identifies the
Animancer.FSM.StateMachine`1.CurrentState . |
Dictionary | IDictionary |
The collection of states mapped to a particular key.
|
GUILineCount | int |
[Editor-Only] The number of standard size lines that
Animancer.FSM.StateMachine`1.DoGUI will use. |
Keys | ICollection |
Gets an
System.Collections.Generic.ICollection`1 containing the keys of the Animancer.FSM.StateMachine`2.Dictionary . |
NextKey | TKey |
The
Animancer.FSM.KeyChange`1.NextKey . |
PreviousKey | TKey |
The
Animancer.FSM.KeyChange`1.PreviousKey . |
this[TKey] | TState |
The state registered with the `key` in the
Animancer.FSM.StateMachine`2.Dictionary . |
Values | ICollection |
Gets an
System.Collections.Generic.ICollection`1 containing the state of the Animancer.FSM.StateMachine`2.Dictionary . |
Methods
Name | Value | Summary |
---|---|---|
Add |
void |
Adds a state to the
Animancer.FSM.StateMachine`2.Dictionary . |
Add |
void |
Adds a state to the
Animancer.FSM.StateMachine`2.Dictionary . |
AddRange |
void |
Adds the specified `keys` and `states`. Both arrays must be the same size.
|
Clear |
void |
Removes all state from the
Animancer.FSM.StateMachine`2.Dictionary . |
Contains |
bool |
Determines whether the
Animancer.FSM.StateMachine`2.Dictionary contains a specific value. |
ContainsKey |
bool |
Determines whether the
Animancer.FSM.StateMachine`2.Dictionary contains a state with the specified `key`. |
CopyTo |
void |
Copies the contents of the
Animancer.FSM.StateMachine`2.Dictionary to the `array` starting at the `arrayIndex`. |
DoGUI |
void |
[Editor-Only] Draws GUI fields to display the status of this state machine in the given `area`.
|
ForceSetState |
TState |
Uses
Animancer.FSM.StateMachine`2.ForceSetState(`0,`1) to change to the state registered with the `key`. If nothing
is registered, it use null and will throw an exception unless
Animancer.FSM.StateMachine`1.AllowNullStates is enabled.
|
ForceSetState |
void |
Calls
Animancer.FSM.IState.OnExitState on the Animancer.FSM.StateMachine`1.CurrentState then changes
to the specified `key` and `state` and calls Animancer.FSM.IState.OnEnterState on it.
|
GetEnumerator |
IEnumerator |
Returns an enumerator that iterates through the
Animancer.FSM.StateMachine`2.Dictionary . |
GetState |
TState |
Returns the state registered with the specified `key`, or null if none is present.
|
Initialize |
void |
Call this after deserializing to properly initialize the
Animancer.FSM.StateMachine`1.CurrentState . |
Remove |
bool |
Removes a state from the
Animancer.FSM.StateMachine`2.Dictionary . |
Remove |
bool |
Removes a state from the
Animancer.FSM.StateMachine`2.Dictionary . |
SetFakeKey |
void |
Sets the
Animancer.FSM.StateMachine`2.CurrentKey without changing the Animancer.FSM.StateMachine`1.CurrentState .
|
ToString |
string |
Returns a string describing the type of this state machine and its
Animancer.FSM.StateMachine`2.CurrentKey and
Animancer.FSM.StateMachine`1.CurrentState .
|
TryGetValue |
bool |
Gets the state registered with the specified `key` in the
Animancer.FSM.StateMachine`2.Dictionary . |
TryResetState |
TState |
Attempts to enter the state registered with the specified `key` and returns it if successful.
|
TryResetState |
bool |
Attempts to enter the specified `state` and returns true if successful.
|
TrySetState |
TState |
Attempts to enter the state registered with the specified `key` and returns it if successful.
|
TrySetState |
bool |
Attempts to enter the specified `state` and returns true if successful.
|