コード例 #1
0
    public static void ClosePlayerMenuScene()
    {
        if (!playerMenuSceneInUse)
        {
            Debug.LogError("Player menu scene trying to be closed while player menu scene not already active");
            return;
        }

        Scene freeRoamScene = sceneRecordStack.Peek().scene;
        FreeRoamSceneController freeRoamSceneController = GetFreeRoamSceneController(freeRoamScene);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            playerMenuSceneInUse = false;

            SceneManager.UnloadSceneAsync(playerMenuScene).completed += (ao) =>
            {
                SceneManager.SetActiveScene(freeRoamScene);

                StartFadeIn();

                FadeInComplete += () =>
                {
                    freeRoamSceneController.SetEnabledState(true);
                };
            };
        };
    }
コード例 #2
0
    public static void ClosePlayerMenuScene()
    {
        if (playerMenuScene == null)
        {
            Debug.LogError("Player menu scene trying to be closed while player menu scene not already active");
            return;
        }

        if (pausedFreeRoamScene == null)
        {
            Debug.LogError("Trying to launch player menu scene while there isn't already a paused scene");
            return;
        }

        FreeRoamSceneController freeRoamSceneController = GetFreeRoamSceneController((Scene)pausedFreeRoamScene);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            SceneManager.UnloadSceneAsync((Scene)playerMenuScene).completed += (ao) =>
            {
                SceneManager.SetActiveScene((Scene)pausedFreeRoamScene);

                ClosePlayerMenuScene_Variables();

                StartFadeIn();

                FadeInComplete += () =>
                {
                    freeRoamSceneController.SetEnabledState(true);
                };
            };
        };
    }
コード例 #3
0
    public static void CloseBattleScene()
    {
        if (!battleSceneInUse)
        {
            Debug.LogError("Battle trying to be closed while battle not already active");
            return;
        }

        Scene freeRoamScene = sceneRecordStack.Peek().scene;
        FreeRoamSceneController freeRoamSceneController = GetFreeRoamSceneController(freeRoamScene);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            PlayerGameObject.GetComponent <PlayerController>().SetMoveDelay(sceneChangePlayerMoveDelay);

            battleSceneInUse = false;

            SceneManager.SetActiveScene(freeRoamScene);

            //Wait until old scene unloaded before starting next scene
            SceneManager.UnloadSceneAsync(battleScene).completed += (ao) =>
            {
                freeRoamSceneController.SetDoorsEnabledState(true);
                freeRoamSceneController.SetEnabledState(true);
                StartFadeIn();
            };
        };
    }
コード例 #4
0
    public static void LaunchTradeScene()
    {
        if (tradeScene != null)
        {
            Debug.LogError("Trade trying to be launched while battle already active");
            return;
        }

        if (pausedFreeRoamScene != null)
        {
            Debug.LogError("Trying to launch trade scene while there is already a paused scene");
            return;
        }

        pausedFreeRoamScene = CurrentScene;
        FreeRoamSceneController pausedSceneController = GetFreeRoamSceneController((Scene)pausedFreeRoamScene);

        pausedSceneController.SetDoorsEnabledState(false);
        pausedSceneController.SetSceneRunningState(false);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            pausedSceneController.SetSceneRunningState(true);
            pausedSceneController.SetEnabledState(false);

            int newSceneIndex = SceneManager.sceneCount;

            AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(tradeSceneIdentifier, LoadSceneMode.Additive);

            loadSceneOperation.completed += (ao) =>
            {
                tradeScene = SceneManager.GetSceneAt(newSceneIndex);

                Trade.TradeManager tradeManager = Trade.TradeManager.GetTradeSceneTradeManager((Scene)tradeScene);

                SceneManager.SetActiveScene((Scene)tradeScene);

                StartFadeIn();

                FadeInComplete += () =>
                {
                    tradeManager.StartTradeScene();
                };
            };
        };
    }
コード例 #5
0
    public static void LaunchBattleScene()
    {
        RefreshCurrentSceneStack();

        if (battleSceneInUse)
        {
            Debug.LogError("Battle trying to be launched while battle already active");
            return;
        }

        Scene freeRoamScene = sceneRecordStack.Peek().scene;
        FreeRoamSceneController freeRoamSceneController = GetFreeRoamSceneController(freeRoamScene);

        freeRoamSceneController.SetDoorsEnabledState(false);
        freeRoamSceneController.SetSceneRunningState(false);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            freeRoamSceneController.SetSceneRunningState(true);
            freeRoamSceneController.SetEnabledState(false);

            //https://low-scope.com/unity-quick-get-a-reference-to-a-newly-loaded-scene/
            int newSceneIndex = SceneManager.sceneCount;

            AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(battleSceneIdentifier, LoadSceneMode.Additive);

            loadSceneOperation.completed += (ao) =>
            {
                battleScene      = SceneManager.GetSceneAt(newSceneIndex);
                battleSceneInUse = true;

                Battle.BattleManager battleManager = Battle.BattleManager.GetBattleSceneBattleManager(battleScene);

                SceneManager.SetActiveScene(battleScene);

                StartFadeIn();

                FadeInComplete += () =>
                {
                    battleManager.StartBattle();
                };
            };
        };
    }
コード例 #6
0
    public static void LaunchPlayerMenuScene(string sceneIdentifier)
    {
        if (playerMenuScene != null)
        {
            Debug.LogError("Player menu scene trying to be launched while player menu scene already active");
            return;
        }

        if (evolutionScene != null || battleScene != null || tradeScene != null)
        {
            Debug.LogWarning("Trying to launch player menu scene whlst battle or trade or evolution scene in use");
        }

        if (pausedFreeRoamScene != null)
        {
            Debug.LogError("Trying to launch player menu scene while there is already a paused scene");
            return;
        }

        pausedFreeRoamScene = CurrentScene;
        FreeRoamSceneController freeRoamSceneController = GetFreeRoamSceneController((Scene)pausedFreeRoamScene);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            freeRoamSceneController.SetEnabledState(false);

            //https://low-scope.com/unity-quick-get-a-reference-to-a-newly-loaded-scene/
            int newSceneIndex = SceneManager.sceneCount;

            AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(sceneIdentifier, LoadSceneMode.Additive);

            loadSceneOperation.completed += (ao) =>
            {
                playerMenuScene = SceneManager.GetSceneAt(newSceneIndex);

                SceneManager.SetActiveScene((Scene)playerMenuScene);

                StartFadeIn();
            };
        };
    }
コード例 #7
0
    /// <summary>
    /// Loads a scene by its identifier, moves the player and player menu and unloads the old scene
    /// </summary>
    /// <param name="sceneIdentifier">The identifier for the scene to load</param>
    /// <param name="oldScene">The old scene to unload</param>
    /// <param name="targetPlayerPosition">The position to place the player in when the scene is loaded</param>
    /// <param name="onComplete">An action to invoke when the new scene is loaded in and the old scene has been unloaded</param>
    private static void LoadScene(string sceneIdentifier,
                                  Scene oldScene,
                                  Vector2Int targetPlayerPosition,
                                  Action onComplete = null)
    {
        FreeRoamSceneController oldSceneFreeRoamController = GetFreeRoamSceneController(oldScene);

        if (oldSceneFreeRoamController != null)
        {
            oldSceneFreeRoamController.SetSceneRunningState(true);
            oldSceneFreeRoamController.SetEnabledState(false);
        }

        int newSceneIndex = SceneManager.sceneCount;

        AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(sceneIdentifier, LoadSceneMode.Additive);

        loadSceneOperation.completed += (ao) =>
        {
            Scene newScene = SceneManager.GetSceneAt(newSceneIndex);

            MovePlayerAndMenuToNewScene(PlayerGameObject,
                                        FreeRoamMenuGameObject,
                                        newScene,
                                        targetPlayerPosition);

            SceneManager.SetActiveScene(newScene);

            GetFreeRoamSceneController(newScene).SetSceneRunningState(false);

            SceneManager.UnloadSceneAsync(oldScene).completed += (ao) =>
            {
                GetFreeRoamSceneController(newScene).SetSceneRunningState(true);
                GetFreeRoamSceneController(newScene).SetDoorsEnabledState(true);
                StartFadeIn();

                onComplete?.Invoke();

                //Autosave once player moved to a new scene (don't do before otherwise they will be in the scene door)
                Saving.Autosave();
            };
        };
    }
コード例 #8
0
    public static void CloseTradeScene()
    {
        if (tradeScene == null)
        {
            Debug.LogError("Trade trying to be closed while battle not active");
            return;
        }

        if (pausedFreeRoamScene == null)
        {
            Debug.LogError("Trying to close trade scene while there is no paused scene to return to");
            return;
        }

        FreeRoamSceneController pausedSceneController = GetFreeRoamSceneController((Scene)pausedFreeRoamScene);

        StartFadeOut();

        FadeOutComplete += () =>
        {
            PlayerGameObject.GetComponent <PlayerController>().SetMoveDelay(sceneChangePlayerMoveDelay);

            SceneManager.SetActiveScene((Scene)pausedFreeRoamScene);

            //Wait until old scene unloaded before starting next scene
            SceneManager.UnloadSceneAsync((Scene)tradeScene).completed += (ao) =>
            {
                pausedSceneController.SetDoorsEnabledState(true);
                pausedSceneController.SetEnabledState(true);

                CloseTradeScene_Variables();

                PlayerGameObject.GetComponent <PlayerController>().PlaySceneAreaMusic();

                StartFadeIn();
            };
        };
    }