Click or drag to resize

FiniteStateMachineT Class

A simple Finite State Machine with states as objects inspired by Prime31's excellent StateKit. If your state classes have an empty constructor, the state machine can create the states automatically when needed (using ChangeStateAutoTState). If not you should create the state instance yourself and register the state in the machine. Whether or not a null state is valid is up to your design.
Inheritance Hierarchy
SystemObject
  Archon.SwissArmyLib.AutomataFiniteStateMachineT

Namespace:  Archon.SwissArmyLib.Automata
Assembly:  Archon.SwissArmyLib (in Archon.SwissArmyLib.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class FiniteStateMachine<T>
Request Example View Source

Type Parameters

T
The type of the context.

The FiniteStateMachineT type exposes the following members.

Constructors
  NameDescription
Public methodFiniteStateMachineT(T)
Public methodFiniteStateMachineT(T, IFsmStateT)
Top
Properties
  NameDescription
Public propertyContext
A shared context which all states have access to.
Public propertyCurrentState
The active state.
Public propertyPreviousState
The previously active state.
Top
Methods
  NameDescription
Public methodChangeStateTState
Changes the active state to the given state type. An instance of that type should already had been registered to use this method.
Public methodChangeStateTState(TState)
Changes the active state to a specific state instance. This will (if not null) also register the state.
Public methodChangeStateAutoTState
Changes the active state to the given state type. If a state of that type isn't already registered, it will automatically create a new instance using the empty constructor.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodIsStateRegistered(Type)
Checks whether a state type is registered.
Public methodIsStateRegisteredTState
Generic version of IsStateRegistered(Type). Checks whether a state type is registered.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRegisterState
Preemptively add a state instance. Useful if the state doesn't have an empty constructor and therefore cannot be used with ChangeStateAuto.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUpdate
Call this every time the machine should update. Eg. every frame.
Top
See Also