/// <summary> /// Callback for a finished async level unload. /// Removes the scene from currentlyUnloadingSceneNames. /// </summary> /// <param name="unloadedScene">Scene that finished unloading</param> void FinishUnloadingScene(Scene unloadedScene) { if (unloadedScene.name == activeSceneName) { debug.LogError("Just unloaded the active scene!"); } AfterSceneUnload?.Invoke(unloadedScene.name); if (currentlyUnloadingSceneNames.Contains(unloadedScene.name)) { currentlyUnloadingSceneNames.Remove(unloadedScene.name); } }
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 }