using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; using System.IO; namespace GeneralTools { public class LoadingManager : SingletonBaseAttribute { protected bool canAddAction = true; public event Action LoadingFinshedListeners; public override void IAwake() { canAddAction = true; } public override void IStart() { StartCoroutine(WaitRegister()); } IEnumerator WaitRegister() { MessageBox.Instance.ShowNotice("正在加载中", "等待组件注册"); yield return new WaitForSeconds(3); canAddAction = false; List loadingListeners = WaitLoadResources.loadingListeners; float progress = 0; int loadNum = loadingListeners.Count; MessageBox.Instance.HideNotice(); //加载注册事件 for (int i = 0; i < loadingListeners.Count; i++) { float p = progress / loadNum; MessageBox.Instance.ShowProgressBar("正在加载中", (p * 100).ToString("F1") + "%", p); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); loadingListeners[i](); progress += 1; yield return new WaitForEndOfFrame(); } MessageBox.Instance.ShowProgressBar("加载完成", "加载完成", 1); yield return new WaitForSeconds(2.0f); MessageBox.Instance.HideProgressBar(); LoadingFinshedListeners?.Invoke(); } } }