Ejemplo n.º 1
0
    /// <summary>Same as Go() but FSM stops after this method</summary>
    /// <param name="nextState">The next state</param>
    /// <param name="theValue">State's argument</param>
    /// <returns></returns>
    public object GoAndStop(STATES nextState, object theValue = null)
    {
        StopAllCoroutines();
        if (onStateExit != null)
        {
            onStateExit();
        }
        onStateExit  = null;
        stateValue   = theValue;
        prevState    = state;
        state        = nextState;
        substate     = string.Empty;
        onStateEvent = null;
        if (logFsm)
        {
            Debug.LogFormat("FSM.GoAndStop: {0}", state);
        }
#if USE_STATE_UPDATE_DELEGATE
        // In case if you need FSM may send message every state change
        if (sendEveryStateMessage && onStateUpdateListeners != null)
        {
            onStateUpdateListeners(new StateUpdateEvent(this));
        }
#endif
        RemoveFSM(this);
        return(null);
    }
Ejemplo n.º 2
0
 /// <summary>Starts the FSM</summary>
 /// <param name="initialState">Initial State</param>
 protected void StartFsm(STATES initialState, object theValue = null)
 {
     state        = initialState;
     stateValue   = theValue;
     onStateEvent = null;
     if (logFsm)
     {
         Debug.LogFormat("FSM.StartFsm: {0}", state);
     }
     AddFSM(this);
 }
Ejemplo n.º 3
0
 /// <summary>Go the specified nextState</summary>
 /// <param name="nextState">The next state</param>
 /// <param name="theValue">State's argument</param>
 public object Go(STATES nextState, object theValue = null)
 {
     StopAllCoroutines();
     if (onStateExit != null)
     {
         onStateExit();
     }
     onStateExit  = null;
     stateValue   = theValue;
     prevState    = state;
     state        = nextState;
     substate     = string.Empty;
     onStateEvent = null;
     if (logFsm)
     {
         Debug.LogFormat("FSM.Go: {0}", state);
     }
     stateStartAt = Time.time;
     AddFSM(this);
     return(null);
 }