Exemplo n.º 1
0
        private IEnumerator TransitionStateRoutine <TV>(TV gameStatePrefab, Action <TV> initializeState = null, Action onStateLoaded = null) where TV : GameState
        {
            PartyParrotManager.Instance.LoadingManager.ShowLoadingScreen(true);

            // this helps give things that need to end *this frame*
            // a chance to do so (the GameOverState is one notorious case of needing this)
            yield return(null);

            IEnumerator exitRunner = ExitCurrentStateRoutine();

            while (exitRunner.MoveNext())
            {
                yield return(null);
            }

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

            initializeState?.Invoke(gameState);

            PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(0.0f, $"Loading game state scene '{gameState.CurrentSceneName}'...");
            yield return(null);

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

            while (runner.MoveNext())
            {
                PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(runner.Current * 0.5f, $"Loading game state scene '{gameState.CurrentSceneName}'...");
                yield return(null);
            }

            PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(0.5f, $"Game state scene '{gameState.CurrentSceneName}' loaded!");
            yield return(null);

            _currentGameState = gameState;
            IEnumerator <LoadStatus> enterRunner = _currentGameState.OnEnterRoutine();

            while (enterRunner.MoveNext())
            {
                LoadStatus status = enterRunner.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, "State transition complete!");
            yield return(null);

            _currentGameState.OnEnter();
            yield return(null);

            onStateLoaded?.Invoke();
            yield return(null);

            PartyParrotManager.Instance.LoadingManager.ShowLoadingScreen(false);
        }
Exemplo n.º 2
0
        private IEnumerator TransitionStateRoutine <TV>(TV gameStatePrefab, Action <TV> initializeState = null, Action onStateLoaded = null) where TV : GameState
        {
            PartyParrotManager.Instance.LoadingManager.ShowLoadingScreen(true);

            IEnumerator exitRunner = ExitCurrentStateRoutine();

            while (exitRunner.MoveNext())
            {
                yield return(null);
            }

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

            initializeState?.Invoke(gameState);

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

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

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

            PartyParrotManager.Instance.LoadingManager.UpdateLoadingScreen(0.5f, "Scene loaded!");
            yield return(null);

            _currentGameState = gameState;
            IEnumerator <LoadStatus> enterRunner = _currentGameState.OnEnterRoutine();

            while (enterRunner.MoveNext())
            {
                LoadStatus status = enterRunner.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, "Done!");
            yield return(null);

            PartyParrotManager.Instance.LoadingManager.ShowLoadingScreen(false);

            onStateLoaded?.Invoke();
        }