Exemplo n.º 1
0
    /// <summary>
    /// Executes a command on the state machine, changing the state
    /// </summary>
    public void Execute(Command cmd, bool SkipTransition = false, bool ForceTransition = false)
    {
        StateRef e_nextState = i_currentState.GetNextState(cmd);
        bool     foundState  = l_validStates.TryGetValue(e_nextState, out i_currentState);

        if (!foundState)
        {
            Debug.Log("ERROR: State Not Found!");
            return;
        }

        // when pausing and unpausing, we want to skip the transition action as, in terms of game physics, the state shouldn't change
        if (SkipTransition)
        {
            sr_currentStateRef = e_nextState;
            return;
        }

        if (e_nextState != sr_currentStateRef || ForceTransition)
        {
            i_currentState.TransitionAct();
            sr_currentStateRef = e_nextState;
        }
    }