using Cysharp.Threading.Tasks;
using Framework;
using PhxhSDK;
namespace Gameplay.SubSystems
{
///
/// 加载管理器
///
public class LoadingManager : Singlenton, IInitable
{
///
/// 当前加载
///
private LoadingExecutor curLoadingExecutor;
///
/// 加载表现
///
private LoadingDisplay loadingDisplay;
#region 进度
///
/// 是否正在运行
///
public bool IsRuning
{
get
{
if (null == curLoadingExecutor)
return false;
return curLoadingExecutor.IsRunning;
}
}
///
/// 实际进度
///
public float Progress
{
get
{
if (null == curLoadingExecutor)
return 0f;
return curLoadingExecutor.Progress;
}
}
///
/// 表现进度
///
public float ShowProgress
{
get
{
if (null == loadingDisplay)
return Progress;
loadingDisplay.Update(Progress);
return loadingDisplay.ShowProgress;
}
}
///
/// 是否等待中
///
public bool IsWait
{
get
{
if (null == curLoadingExecutor)
return true;
return curLoadingExecutor.IsWait;
}
set
{
curLoadingExecutor.IsWait = value;
}
}
#endregion
public void Init()
{
loadingDisplay = new();
}
public void Release()
{
loadingDisplay = null;
}
///
/// 开始加载
///
///
///
///
///
public async UniTask ExecuteLoading(LoadingExecutor executer, float changeProgressTime = 1f, float loadingCompleteWaitTime = 0.2f)
{
if (null == executer)
{
DebugUtil.LogError("错误,启动空的加载器");
return;
}
if (IsRuning)
{
DebugUtil.LogError("错误,有加载器没有加载完");
return;
}
loadingDisplay.SetInfo(changeProgressTime, loadingCompleteWaitTime);
curLoadingExecutor = executer;
await curLoadingExecutor.Excute(changeProgressTime + loadingCompleteWaitTime);
}
}
///
/// loading界面类型
///
public enum E_LoadingType
{
///
/// 登录游戏
///
Login,
///
/// 通用加载
///
CommonLoading,
}
///
/// 加载结果
///
public enum E_LoadingResult
{
///
/// 完成加载
///
Success = 0,
///
/// 加载出错(测试)
///
ErrorTest = 1,
///
/// 启动游戏时网络连接出错
///
GameStartSevNetError = 2,
///
/// 当前设备网络问题
///
DeviceNetError = 3,
}
}