StateMachine
Represents the core definition of a state machine and defines its behavior.
Read time 2 minutesLast updated 7 days ago
Definition
- Type: Class
- Namespace: Unity.GraphToolkit.Editor
- Assembly: UnityEditor
public class StateMachine
Remarks
StateMachine-
Lifecycle management (via StateMachine.OnEnable, StateMachine.OnDisable)
-
Change tracking (via StateMachine.OnStateMachineChanged)
-
Access to states and variables
To register a state machine type and associate it with a custom file extension and configuration options, apply the StateMachineAttribute to your custom class.
StateMachineYou can further control the state machine's behavior using the StateMachineOptions enum, which defines traits.
Use the StateMachineDatabase utility class to create, load, and save state machine assets in the Unity Editor. State machines are serialized assets. You can create them through the editor UI with StateMachineDatabase.PromptInProjectBrowserToCreateNewAsset or load them from disk with StateMachineDatabase.LoadStateMachine.
Properties
Property | Description |
|---|---|
| AssetGuid | The |
| AvailableVariableTypes | The set of types offered in the blackboard for variable creation. |
| ID | The globally unique identifier for this state machine. |
| Name | The name of the state machine. |
| StateCount | The number of IStates in the state machine. |
| VariableCount | The number of IVariables declared in the state machine. |
Methods
Method | Description |
|---|---|
| AddState | Adds a state to the state machine. |
| BuildAvailableVariableTypes | Builds the set of variable types offered in the blackboard for variable creation. |
| Connect | Creates a transition from one state to another. |
| CreateVariable | Creates and adds a new variable to the state machine. |
| Disconnect | Removes all transitions that go from one state to another. |
| GetState | Retrieves a state in the state machine by its index. |
| GetStates | Retrieves all states in the state machine. |
| GetTransitions | Retrieves the transitions that connect one state to another. |
| GetVariable | Retrieves a variable declared in the state machine by index. |
| GetVariables | Retrieves all variables declared in the state machine. |
| OnDisable | Called when the state machine is unloaded, or goes out of scope in the editor. |
| OnEnable | Called when the state machine is created or loaded in the editor. |
| OnStateMachineChanged | Called after the state machine has changed. |
| RemoveState | Removes a state from the state machine. |
| RemoveVariable | Removes a variable from the state machine. |
| UndoBeginRecordStateMachine | Signals the beginning of an undoable operation. |
| UndoEndRecordStateMachine | Signals the end of an undoable operation. Sends the undo data to the editor undo system and refreshes the graph view with the changes made. |