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; } }
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)); } }
// 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))); }
/// <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))); }
/// <summary> /// Unloads any scene that is not the selected scene or connected to it as defined by the world graph. /// </summary> /// <param name="selectedScene"></param> void DeactivateUnrelatedScenes(string selectedScene, bool serializeDeactivatingScenes) { List <string> scenesToDeactivate = new List <string>(); foreach (string currentlyActiveScene in loadedSceneNames) { if (currentlyActiveScene != selectedScene && !levels[selectedScene].connectedLevels.Exists(l => enumToSceneName[l] == currentlyActiveScene)) { scenesToDeactivate.Add(currentlyActiveScene); } } if (serializeDeactivatingScenes) { foreach (var sceneToDeactivate in scenesToDeactivate) { BeforeSceneSerializeState?.Invoke(sceneToDeactivate); } } if (serializeDeactivatingScenes) { foreach (string sceneToDeactivate in scenesToDeactivate) { SaveManagerForScene saveForScene = SaveManager.GetOrCreateSaveManagerForScene(sceneToDeactivate); saveForScene.SerializeStateForScene(); } } // Update internal state before starting any unload scene calls foreach (var sceneToDeactivate in scenesToDeactivate) { loadedSceneNames.Remove(sceneToDeactivate); currentlyUnloadingSceneNames.Add(sceneToDeactivate); } foreach (var sceneToDeactivate in scenesToDeactivate) { BeforeSceneUnload?.Invoke(sceneToDeactivate); } foreach (var sceneToDeactivate in scenesToDeactivate) { SceneManager.UnloadSceneAsync(sceneToDeactivate); } }
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 FadeAndSwitchScenes(string sceneName) { // fade to black and wait for that to finsih yield return(StartCoroutine(Fade(1f))); // call Scene Events BeforeSceneUnload?.Invoke(); int oldScene = SceneManager.GetActiveScene().buildIndex; yield return(StartCoroutine(LoadSceneAndSetActive(sceneName))); //unload current scene and wait for that to finish yield return(SceneManager.UnloadSceneAsync(oldScene)); //if this event has any subscribers, call it. AfterSceneUnload?.Invoke(); yield return(StartCoroutine(Fade(0f))); //fade to new scene after scene is loaded }
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))); }