Пример #1
0
        /// <summary>
        /// Delete the current state, and activate the one bellow that.
        /// </summary>
        internal void PopState()
        {
            if (_states.Count < 2)
            {
                throw new StackOverflowException();
            }

            _states.Peek().OnExit();
            OnStateExit?.Invoke(_states.Peek());
            _states.Pop();

            var currentState = _states.Peek();

            State.InitStateManager(this);
            currentState.OnEnter();
            OnStateChanged?.Invoke(currentState);
        }
Пример #2
0
        /// <summary>
        /// Calls OnExit on the current state (without Popping it), then Add a new one.
        /// </summary>
        internal void PushState(State state)
        {
            if (state == null)
            {
                Debug.LogWarning("[StateManager] Trying to Push a null state");
                return;
            }

            if (_states.Count > 0)
            {
                _states.Peek().OnExit();
                OnStateExit?.Invoke(_states.Peek());
            }

            _states.Push(state);
            State.InitStateManager(this);
            _states.Peek().OnEnter();
            OnStateChanged?.Invoke(state);
        }