When an FSM state is Entered, Updated or Exited, you can receive callbacks on your MonoBehaviours attached to the same game object as the FSMOwner. The callbacks that can be used are the following:
To do so, you need to implement the ‘IStateCallbackReceiver’ interface in your MonoBehaviour. Here is a code example for your convenience.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
using UnityEngine; public class StateCallbacksExample : MonoBehaviour, IStateCallbackReceiver { public void OnStateEnter(IState state){ } public void OnStateUpdate(IState state){ } public void OnStateExit(IState state){ } } |
IState is an interface having information about the current state the callback is called for.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public interface IState{ //The name of the state string name {get;} //The tag of the state string tag {get;} //The elapsed time of the state float elapsedTime {get;} //The FSM this state belongs to FSM FSM {get;} //An array of the state's transition connections FSMConnection[] GetTransitions(); //Evaluates the state's transitions and returns true if a transition has been performed bool CheckTransitions(); } |
These callbacks are not meant to be used for modeling a whole state, but rather to get notified and perform some extra actions you might need to do.
© Paradox Notion 2014-2024. All rights reserved.