Пример #1
0
    public void ChangeState(FSMTransition stateTransition) {
        Enum nextStateId = stateTransition.NextStateId;

        FSMState prevState = CurrentState;

        if(nextStateId == null) {
            CurrentState = _stateStack.Pop();
        } else {
            FSMState nextState = GetState(nextStateId);

            if(nextState == null)
                throw new Exception("State " + nextStateId.ToString() + " has not been defined.");

            if(stateTransition.PushCurrentState)
                _stateStack.Push(CurrentState);

            CurrentState = nextState;

            CurrentState.InitState(stateTransition);
        }

        Debug.Log("Changed state to: " + CurrentState.StateId.ToString());

        CurrentState.EnterState(stateTransition);

        if(prevState != null && !stateTransition.PushCurrentState)
            prevState.Dispose();
    }