Difference between revisions of "FSMState"
(Initial page, includes API information and categories) |
Latest revision as of 21:25, 16 April 2013
This class works closely with the FSMSystem to implement a flexible Finite State Machine framework for Unity. It is based on work from the Unify Community Wiki: Finite State Machine.
A class deriving from this class should be created for every state in the state machine. These classes are where the states have the chance to implement behavior specific to what should happen in that class. See PathEnemyStates for a working example of this.
Contents |
[edit] Abstract Functions
These functions must be implemented by deriving classes, otherwise you'll get compiler errors.
[edit] void Reason (GameObject player, GameObject npc)
This method decides if the state should transition to another on its list.
[edit] void Act (GameObject player, GameObject npc)
This method controls the behavior of the NPC in the game world. Every action, movement or communication the NPC does should be placed here.
[edit] Virtual Functions
These functions can be overridden to extend the behavior of this class.
[edit] void DoBeforeEntering(GameObject player, GameObject npc)
This method can be used to set up the State before entering it. It is called automatically by the FSMSystem class before assigning it as the current state.
[edit] void DoBeforeLeaving(GameObject player, GameObject npc)
This method can be used to reset anything in the state, or perform final actions for the state, before the FSMSystem transitions to a new state. It is called automatically by the FSMSystem before changing to a new state.
[edit] Public Functions
[edit] void AddTransition(T trans, S id)
This adds a transition to the state. It takes a Transition enum value, and a corresponding StateID enum value. When this state is told to perform the transition specified, it will tell the state machine to go to the state with the StateID specified here.
[edit] void DeleteTransition(T trans)
This deletes a given transition.
[edit] S GetOutputState(T trans)
This looks up a StateID enum value for a given Transition.
[edit] int CompareTo (object other)
This compares one state object to another by comparing the StateID enum values of the states.
[edit] void PerformTransition(T trans)
This calls into the state machine to tell it to do the specified transition.
[edit] Public Variables
[edit] StateID ID
This returns the ID enum value of this state. Read-Only.
[edit] stateMachine : FSMSystem <T,S>
This is public so the state machine may set itself in this class when the state is added to the state machine. It is here to provide an easy way to initiate transitions from within the state itself. It shouldn't be changed at runtime.