Files
plugin-library/Assets/Domain/Test/HotUpdate/Application/UIViews/Loading.cs
2025-09-24 15:34:24 +08:00

94 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using UnityEngine;
namespace Stary.Evo
{
public class LoadingData
{
public LoadingFunc loadingFunc;
public bool isCleanupAsset = false;
}
public delegate IEnumerator LoadingFunc(Action<float, string> loadingRefresh);
/// <summary>
/// 实际游戏中的loading
/// </summary>
public class Loading : SingletonMono<Loading>
{
private LoadingData _loadingData;
private Coroutine _cor;
public void StartLoading(LoadingFunc loadingFunc, bool isCleanupAsset = false)
{
StartLoading(new LoadingData { loadingFunc = loadingFunc, isCleanupAsset = isCleanupAsset });
}
private void StartLoading(LoadingData loadingData)
{
//开启UI
UIManager.Instance.Open<UILoadingView>();
if (loadingData.loadingFunc != null)
{
_loadingData = loadingData;
if (_cor != null)
{
StopCoroutine(_cor);
}
_cor = StartCoroutine(CorLoading());
}
else
{
Debug.LogError("加载错误,没有参数LoadingData");
}
}
private IEnumerator CorLoading()
{
yield return StartCoroutine(_loadingData.loadingFunc(RefreshLoading));
// if (_loadingData != null && _loadingData.isCleanupAsset)
// {
// yield return ResourceManager.Instance.GetResourceCore(UIConfig.UIPackageName).CleanupAsync();
// yield return Resources.UnloadUnusedAssets();
// }
// Pool.ReleaseAll();
// yield return null;
GC.Collect();
yield return null;
Exit();
_cor = null;
}
private void RefreshLoading(float loading, string desc)
{
// 刷新
var view = UIManager.Instance.GetView<UILoadingView>();
if (view != null)
{
view.SetLoading(loading, desc);
}
if (!string.IsNullOrEmpty(desc))
{
Debug.Log(desc);
}
}
private void Exit()
{
// 关闭UI
UIManager.Instance.Close<UILoadingView>();
ObjectPool<LoadingData>.Release(_loadingData);
_loadingData = null;
}
}
}