Exemple #1
0
    private IEnumerator FadeAndSwitchScenes(string sceneName)
    {
        yield return(StartCoroutine(Fade(1f)));

        BeforeSceneUnload?.Invoke();
        yield return(SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex));

        yield return(StartCoroutine(LoadSceneAndSetActive(sceneName)));

        if (sceneName == mainMenuName)
        {
            settingsButton.SetActive(true);
            homeButton.SetActive(true);
        }
        LevelSelect.gameObject.SetActive(false);
        AfterSceneLoad?.Invoke();
        yield return(StartCoroutine(Fade(0f)));

        if (PuzzleMaster.instance != null && !newGame && inMenu)
        {
            PuzzleMaster.onPuzzleComplete += OpenLevelSelect;
            inMenu = false;
        }
        else if (PuzzleMaster.instance != null)
        {
            PuzzleMaster.onPuzzleComplete += BeginAdvanceToNextLevel;
            newGame = false;
            inMenu  = false;
        }
    }
Exemple #2
0
        private IEnumerator DoFadeAndSwitchScenes(string[] sceneNamesToLoad, string[] sceneNamesToUnload)
        {
            yield return(StartCoroutine(Fade(1f, this.fadeDuration)));

            BeforeSceneUnload?.Invoke();
            if (IsDebriefing(sceneNamesToLoad))
            {
                MoveCharactersToVault();
                foreach (GameObject gameObject in hiddenInDebriefing)
                {
                    gameObject.SetActive(false);
                }
            }

            yield return(StartCoroutine(UnloadScenes(sceneNamesToUnload)));

            yield return(StartCoroutine(LoadScenes(sceneNamesToLoad)));

            AfterSceneLoad?.Invoke();

            if (!ShowChapterInfo(sceneNamesToLoad))
            {
                StartCoroutine(Fade(0f, this.fadeDuration));
            }
        }
Exemple #3
0
        /// <summary>
        /// Callback for a finished async level load.
        /// Marks scene as active if it's name matches activeSceneName.
        /// Removes scene name from currentlyLoadingSceneNames and adds it to loadedSceneNames.
        /// </summary>
        /// <param name="loadedScene">Scene that finished loading</param>
        void FinishLoadingScene(Scene loadedScene)
        {
            if (loadedScene.name == ManagerScene)
            {
                return;
            }

            if (loadedScene.name == activeSceneName)
            {
                SceneManager.SetActiveScene(loadedScene);
                OnActiveSceneChange?.Invoke();
            }

            AfterSceneLoad?.Invoke(loadedScene.name);

            if (currentlyLoadingSceneNames.Contains(loadedScene.name))
            {
                currentlyLoadingSceneNames.Remove(loadedScene.name);
            }

            if (!loadedSceneNames.Contains(loadedScene.name))
            {
                loadedSceneNames.Add(loadedScene.name);
            }
        }
Exemple #4
0
    // This is the coroutine where the 'building blocks' of the script are put together.
    private IEnumerator FadeAndSwitchScenes(string sceneName)
    {
        // Start fading to black and wait for it to finish before continuing.
        yield return(StartCoroutine(Fade(1f)));

        loadingText.text    = "Loading " + sceneName + "...";
        loadingText.enabled = true;

        // If this event has any subscribers, call it.
        BeforeSceneUnload?.Invoke();

        previousSceneName = SceneManager.GetActiveScene().name;

        // Unload the current active scene.
        yield return(SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex));

        // Start loading the given scene and wait for it to finish.
        yield return(StartCoroutine(LoadSceneAndSetActive(sceneName)));

        // If this event has any subscribers, call it.
        AfterSceneLoad?.Invoke();

        loadingText.enabled = false;

        // Start fading back in and wait for it to finish before exiting the function.
        yield return(StartCoroutine(Fade(0f)));
    }
Exemple #5
0
    public IEnumerator LoadFirstScene()
    {
        loadingText.text    = "Loading...";
        loadingText.enabled = true;
        // Start the first scene loading and wait for it to finish.
        yield return(StartCoroutine(LoadSceneAndSetActive(startingSceneName)));

        AfterSceneLoad?.Invoke();

        loadingText.enabled = false;
        // Once the scene is finished loading, start fading in.
        StartCoroutine(Fade(0f));
    }
    /// <summary>
    /// Swaps out the scenes
    /// </summary>
    /// <param name="sceneName">The scene to change to</param>
    private IEnumerator SwitchScenes(string sceneName)
    {
        yield return(StartCoroutine(Fade(1f)));

        BeforeSceneUnload?.Invoke();

        yield return(SceneManager.UnloadSceneAsync(
                         SceneManager.GetActiveScene().buildIndex));

        yield return(StartCoroutine(LoadSceneAndSetActive(sceneName)));

        AfterSceneLoad?.Invoke();

        yield return(StartCoroutine(Fade(0f)));
    }
    private IEnumerator FadeAndSwitchScenes(string sceneName)
    {
        yield return(StartCoroutine(Fade(1f)));

        BeforeSceneUnload?.Invoke();

        if (SceneManager.GetActiveScene().name != Constants.persistentSceneName)
        {
            SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().name);
        }

        yield return(StartCoroutine(LoadSceneAndSetActive(sceneName)));

        AfterSceneLoad?.Invoke();

        yield return(StartCoroutine(Fade(0f)));
    }
    private IEnumerator fadeAndSwitchScene(string sceneName)
    {
        PlayerInputScript player = FindObjectOfType <PlayerInputScript>();

        player.setHighlightedInventoryItemToNull();
        player.setHighlightedWorldObjectToNull();

        yield return(StartCoroutine(fade(1f)));

        closeMapScreen();

        BeforeSceneUnload?.Invoke(); // calls all functions that are 'subscibed' to the BeforeSceneUnload function

        yield return(SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex));

        yield return(StartCoroutine(loadSceneAndSetActive(sceneName)));

        AfterSceneLoad?.Invoke();

        yield return(StartCoroutine(fade(0f)));
    }