Exemplo n.º 1
0
    public void GotoNewState(BehaviourState newState, TransitionMode transitionMode)
    {
        BehaviourState oldState = currentState;
        oldState.ExitState(owner);

        #if VERBOSE_AI_STATES
        Debug.Log("AI state change: [" + oldState.GetType().Name + "] --> [" + newState.GetType().Name + "] :: <" + transitionMode + ">");
        #endif

        switch(transitionMode) {
            case TransitionMode.PopPrevious:
                // Go back to the previous state on the stack
                BehaviourState nextState = stateStack.Pop();
                if(nextState != null) {
                    currentState = nextState;
                }
                else {
                    // in case there was no state on the stack, go back to base state
                    currentState = baseState;
                }
                break;
            case TransitionMode.PushCurrent:
                // Pushes the current state onto the stack and goes to the returned next state
                stateStack.Push(currentState);
                currentState = newState;
                if(currentState == null) {
                    // If a null state was added, go back tot eh previous one
                    currentState = stateStack.Pop();
                }
                break;
            case TransitionMode.AbandonCurrent:
                // Go to the new state, without pushing the current one on the stack
                if(newState != null) {
                    currentState = newState;
                }
                break;
        }

        currentState.EnterState(owner);
    }