Exemple #1
0
        public void PopSubState()
        {
            SubGameState previousState = _currentSubGameState;

            _currentSubGameState = null;

            if (null != previousState)
            {
                previousState.OnExit();

                // TODO: this should disable the state rather than destroying it
                Destroy(previousState.gameObject);
            }

            _currentSubGameState = _subStateStack.Count > 0 ? _subStateStack.Pop() : null;

            if (null != _currentSubGameState)
            {
                _currentSubGameState.OnResume();
            }
            else if (null != _currentGameState)
            {
                _currentGameState.OnResume();
            }
        }
Exemple #2
0
        public void PushSubState <TV>(TV gameStatePrefab, Action <TV> initializeState = null) where TV : SubGameState
        {
            if (null != _currentSubGameState)
            {
                _currentSubGameState.OnPause();
            }
            else if (null != _currentGameState)
            {
                _currentGameState.OnPause();
            }

            // enqueue the current state if we have one
            if (null != _currentSubGameState)
            {
                _subStateStack.Push(_currentSubGameState);
            }

            // new state is now the current state
            // TODO: this should enable the state from the set rather than allocating
            TV gameState = Instantiate(gameStatePrefab, transform);

            initializeState?.Invoke(gameState);

            _currentSubGameState = gameState;
            _currentSubGameState.OnEnter();
        }
Exemple #3
0
        public void PopSubState()
        {
            SubGameState previousState = (SubGameState)_currentGameState;

            _currentGameState = null;

            previousState?.OnExit();
            Destroy(previousState?.gameObject);

            _currentGameState = _stateQueue.Count > 0 ? _stateQueue.Dequeue() : null;
        }
Exemple #4
0
        public void PopSubState()
        {
            SubGameState previousState = (SubGameState)_currentGameState;

            _currentGameState = null;

            if (null != previousState)
            {
                previousState.OnExit();
                Destroy(previousState.gameObject);
            }

            _currentGameState = _stateStack.Count > 0 ? _stateStack.Pop() : null;
            _currentGameState?.OnResume();
        }
Exemple #5
0
        public void PushSubState(SubGameState gameStatePrefab, Action <SubGameState> initializeState = null)
        {
            // enqueue the current state if we have one
            if (null != _currentGameState)
            {
                _stateQueue.Enqueue(_currentGameState);
            }

            // new state is now the current state
            // TODO: this should enable the state from the set rather than allocating
            SubGameState gameState = Instantiate(gameStatePrefab, transform);

            initializeState?.Invoke(gameState);

            _currentGameState = gameState;
            _currentGameState.OnEnter();
        }