Update SceneManager (WIP)

This commit is contained in:
CroakFang
2023-07-04 19:24:15 +08:00
parent 1a49208ad2
commit cf5b45aa35
22 changed files with 1639 additions and 303 deletions
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class UmaSceneController:MonoBehaviour
{
public static UmaSceneController instance;
private void Awake()
{
if (instance)
{
Destroy(this.gameObject);
}
instance = this;
DontDestroyOnLoad(this);
}
public void LoadScene(string name, Action onNewSceneLoaded, Action onPrevSceneUnLoaded)
{
StartCoroutine(LoadLiveSceneAsync("LiveScene", onNewSceneLoaded, onPrevSceneUnLoaded));
}
IEnumerator LoadLiveSceneAsync(string sceneName, Action onNewSceneLoaded, Action onPrevSceneUnLoaded)
{
AsyncOperation asyncTransitionLoad = SceneManager.LoadSceneAsync("TransitionScene", LoadSceneMode.Additive);
yield return new WaitUntil(() => asyncTransitionLoad.isDone);
Animation loadingCanvas = GameObject.Find("LoadingCanvas").GetComponent<Animation>();
loadingCanvas.Play("SceneTransition_s");
yield return new WaitUntil(() => !loadingCanvas.isPlaying);
// Set the current Scene to be able to unload it later
Scene currentScene = SceneManager.GetActiveScene();
// The Application loads the Scene in the background at the same time as the current Scene.
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
// Wait until the last operation fully loads to return anything
yield return new WaitUntil(()=> asyncLoad.isDone);
onNewSceneLoaded.Invoke();
// Unload the previous Scene
AsyncOperation asyncUnLoad = SceneManager.UnloadSceneAsync(currentScene);
yield return new WaitUntil(() => asyncUnLoad.isDone);
onPrevSceneUnLoaded.Invoke();
loadingCanvas.Play("SceneTransition_e");
yield return new WaitUntil(() => !loadingCanvas.isPlaying);
// Unload the Transition Scene
AsyncOperation asyncTransitionUnLoad = SceneManager.UnloadSceneAsync("TransitionScene");
yield return new WaitUntil(() => asyncTransitionUnLoad.isDone);
}
}