//异步场景加载完成 private void AsyncLoading_completed(UnityEngine.AsyncOperation obj) { updateLoading?.Invoke(obj.progress); endLoading?.Invoke(); MTEvent.EventParamete eventParamete = new MTEvent.EventParamete(); eventParamete.AddParameter(obj.progress); EventManager.TriggerEvent(MTEvent.GenericEventEnumType.Message, LoadingMessageType.LoadingProcess.ToString(), eventParamete); }
/// <summary> /// 异步加载场景 /// </summary> /// <param name="levelName">场景名字</param> /// <param name="startLoading">开始回调</param> /// <param name="endLoading">结束回调</param> /// <param name="loadSceneMode">加载类型</param> public IEnumerator LoadSceneAsync(string levelName, Action _startLoading = null, Action <float> _updateLoading = null, Action _endLoading = null, LoadingType loadingType = LoadingType.Single) { UnityEngine.AsyncOperation asyncOperation = default(UnityEngine.AsyncOperation); switch (loadingType) { case LoadingType.Additive: asyncOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelName, UnityEngine.SceneManagement.LoadSceneMode.Additive); break; case LoadingType.Single: asyncOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelName, UnityEngine.SceneManagement.LoadSceneMode.Single); break; default: break; } asyncOperation.completed += AsyncLoading_completed; startLoading = _startLoading; updateLoading = _updateLoading; endLoading = _endLoading; startLoading?.Invoke(); while (!asyncOperation.isDone) { updateLoading?.Invoke(asyncOperation.progress); MTEvent.EventParamete eventParamete = new MTEvent.EventParamete(); eventParamete.AddParameter(asyncOperation.progress); EventManager.TriggerEvent(MTEvent.GenericEventEnumType.Message, LoadingMessageType.LoadingProcess.ToString(), eventParamete); yield return(new WaitForFixedUpdate()); } yield return(asyncOperation); }