using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Accessibility; using UnityEngine.SceneManagement; public class SceneOverlayManager : MonoBehaviour { public static SceneOverlayManager Instance; public string _normal_scene = "深圳市民中心_白天_HD"; string _last_loaded_scene; private List operations = new List(); private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); } else { if (Instance != this) { Debug.Log("warning: multiple Manager creating!"); GameObject.Destroy(gameObject); } } } // Start is called before the first frame update void Start() { //if (!string.IsNullOrEmpty(_normal_scene)) //{ // LoadSceneAsync(_normal_scene); //} //if (GameInit.Instance == null) // LoadSceneAsync("深圳市民中心_白天_HD", true, (_async) => // { // LoadSceneAsync("无人机组件控制器", false); // }); } /// /// 异步加载场景 /// /// 场景名 /// 是否卸载上一个加载的场景 /// 加载完成回调事件 /// 卸载完成回调事件 /// 加载模式 public void LoadSceneAsync(string _load_scene_name, bool _unload_last_scene = true, Action _load_complete_callback = null, Action _unload_complete_callback = null, LoadSceneMode _load_scene_mode = LoadSceneMode.Additive) { try { //卸载上一个场景 if (_unload_last_scene) { if (!string.IsNullOrEmpty(_last_loaded_scene) && _load_scene_name != _last_loaded_scene) { var _unload_async = SceneManager.UnloadSceneAsync(_last_loaded_scene); _unload_async.completed += _unload_complete_callback; } } } catch (Exception e) { } //加载目标场景 var _load_scene = SceneManager.GetSceneByName(_load_scene_name); if (_load_scene != null && !_load_scene.isLoaded) { var _load_async = SceneManager.LoadSceneAsync(_load_scene_name, _load_scene_mode); _load_async.completed += _load_complete_callback; } if (_unload_last_scene) _last_loaded_scene = _load_scene_name; } }