Beispiel #1
0
    /// <summary>
    /// A call to transition to the nextState passed in.
    /// </summary>
    /// <param name="nextState"> the desired state to transition to. </param>
    public void TransitionToState(StateTypes nextState)
    {
        IBaseState battleState = GetNextState(nextState);

        currentState.OnExit();

        currentState = battleState;

        currentState.OnEnter();
    }
        public void StartState(Type stateType)
        {
            IBaseState state = GetState(stateType);

            if (state == null)
            {
                throw new Exception($"can not state '{stateType.FullName}' which is not exist.");
            }

            _currentState     = state;
            _currentStateTime = 0;
            _currentState.OnEnter();
        }
        public void ChangeState(Type stateType)
        {
            if (stateType == _currentState.GetType())
            {
                Debug.Log($"state '{stateType.FullName}' is running.");
                return;
            }

            IBaseState state = GetState(stateType);

            if (state == null)
            {
                throw new Exception($"can not state '{stateType.FullName}' which is not exist.");
            }

            _currentState.OnLeave();
            _currentState     = state;
            _currentStateTime = 0;
            _currentState.OnEnter();
        }