public virtual void Launch(ConnectionMode mode)
        {
            //The player's pokemon should be healed before network battles
            PlayerData.singleton.HealPartyPokemon();

            if (defaultSelectedGameObject != null)
            {
                EventSystem.current.SetSelectedGameObject(defaultSelectedGameObject);
            }

            sceneController.SetSceneRunningState(false);
            Show();
        }
示例#2
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();
                };
            };
        };
    }
    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();
                };
            };
        };
    }
示例#4
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();
            };
        };
    }