using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; public class ScenesManager { public ScenesManager() { } /// /// 同步加载场景 /// /// 场景名称 /// 场景加载后需要做的 public void LoadScene(string sceneName, UnityAction action = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { SceneManager.LoadScene(sceneName, loadSceneMode); action?.Invoke(); } /// /// 异步加载场景 /// /// 场景名称 /// 委托 /// 加载场景方式 public void LoadSceneAsyn(MonoBehaviour taget, string sceneName, UnityAction action = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { taget.StartCoroutine(ReallyLoadScene(sceneName, action)); } /// /// 协程加载场景 /// /// 场景名称 /// 委托 /// 加载场景方式 /// private IEnumerator ReallyLoadScene(string sceneName, UnityAction action = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { AsyncOperation ao = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); while (!ao.isDone) { action?.Invoke(); yield return null; } } }