DCS/ruiyiweiUX/Assets/GeneralTools/Scripts/Always/LoadingManager.cs

53 lines
1.8 KiB
C#
Raw Permalink Normal View History

2026-06-09 13:59:11 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.IO;
namespace GeneralTools
{
public class LoadingManager : SingletonBaseAttribute<LoadingManager>
{
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<Action> 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();
}
}
}