FSMSystem

From Headbone Creative
Jump to: navigation, search

The FSMSystem is a modified version of the Finite State Machine system found here on the Unify Community wiki: Finite State Machine.

It has been modified here to use Generics, and therefore can be re-used without having to be copied and pasted each time. Instead, to use it now, put your state classes and enums in their own namespace, and use that namespace on your FSM driver class. See PathEnemyFSM and PathEnemyStates for the example from the Unity wiki updated to use this new system.

This page is the API for the FSMSystem class. See FSMState for the API for the individual states that are added to this class.

Contents

Public Variables

StateID CurrentStateID

This returns the StateID of the current state. Read-Only.

FSMState<T, S> CurrentState

This returns the FSMState object of the current state. Read-Only.

Protected Variables

player : GameObject

This is the object of the player. It is generally used to create interactions between the npc and the player. See SetPlayer, below.

npc : GameObject

This is the object of the npc. It is generally used to create interactions between the player and npc (the object this state machine is attached to). See SetNPC, below.

Public Functions

void AddState (FSMState<T, S> s)

This adds a state to the list of states in this state machine. This must be done for every state object in the state machin, otherwise errors will occur when trying to transition to a state that hasn't been added using this method.

void DeleteState (S id)

This takes the StateID enum value and deletes the corresponding state from the list.

void PerformTransition (T trans)

This takes a Transition enum value and attempts to perform that transition on the current state. An error is printed to the debug console if the current state isn't expecting this type of transition.

void ProcessCurrentState ()

This function should be called to drive the state machine. It calls Reason() and then Act() on the current state.

Usually this function is called from Update or FixedUpdate of the class that initialized this instance of FSMSystem.

void SetPlayer (GameObject _player)

This is called to set the player object, which is then passed into Reason() and Act() in ProcessCurrentState().

void SetNPC (GameObject _npc)

This is called to set the npc object, which is then passed into Reason() and Act() in ProcessCurrentState().

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox