using Cysharp.Threading.Tasks; using Framework; using PhxhSDK; using UnityEngine; 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; } changeProgressTime = Mathf.Max(0f, changeProgressTime); loadingCompleteWaitTime = Mathf.Max(0f, loadingCompleteWaitTime); loadingDisplay.SetInfo(changeProgressTime); curLoadingExecutor = executer; await curLoadingExecutor.Excute(changeProgressTime + loadingCompleteWaitTime); } } /// /// loading界面类型 /// public enum E_LoadingType { /// /// 登录游戏 /// Login, /// /// 通用加载 /// CommonLoading, /// /// 通用快速黑屏加载 /// QuickBlack, } /// /// 加载结果 /// public enum E_LoadingResult { /// /// 完成加载 /// Success = 0, /// /// 加载出错(测试) /// ErrorTest = 1, /// /// 启动游戏时网络连接出错 /// GameStartSevNetError = 2, /// /// 当前设备网络问题 /// DeviceNetError = 3, } }