Exemplo n.º 1
0
        private void ExitCurrentState(Action callback)
        {
            if (null == _currentGameState)
            {
                callback?.Invoke();
                return;
            }

            while (_stateStack.Count > 0 && !(_currentGameState is GameState))
            {
                PopSubState();
            }

            GameState gameState = (GameState)_currentGameState;

            _currentGameState = null;

            gameState.UnloadScene(() => {
                if (null != gameState)
                {
                    gameState.OnExit();

                    // TODO: disable the state, don't destroy it
                    Destroy(gameState.gameObject);
                }

                callback?.Invoke();
            });
        }
Exemplo n.º 2
0
        private void ExitCurrentState()
        {
            _currentGameState?.OnExit();

            Destroy(_currentGameState?.gameObject);
            _currentGameState = null;
        }
Exemplo n.º 3
0
        private IEnumerator ExitCurrentStateRoutine()
        {
            while (null != _currentSubGameState || _subStateStack.Count > 0)
            {
                PopSubState();
            }

            if (null == _currentGameState)
            {
                yield break;
            }

            _currentGameState.OnExit();

            GameState gameState = _currentGameState;

            _currentGameState = null;

            PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(0.0f, "Unloading current scene...");
            yield return(null);

            IEnumerator <float> runner = gameState.UnloadSceneRoutine();

            while (runner.MoveNext())
            {
                PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(runner.Current * 0.5f, "Unloading current scene...");
                yield return(null);
            }

            PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(0.5f, "Unloading current scene...");
            yield return(null);

            IEnumerator <LoadStatus> exitRunner = gameState.OnExitRoutine();

            while (exitRunner.MoveNext())
            {
                LoadStatus status = exitRunner.Current;
                if (null != status)
                {
                    PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(0.5f + status.LoadPercent * 0.5f, status.Status);
                }
                yield return(null);
            }

            PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(1.0f, "Current scene unloaded!");
            yield return(null);

            // TODO: disable the state, don't destroy it
            Destroy(gameState.gameObject);
        }