using Cysharp.Threading.Tasks; using UnityEngine; namespace PhxhSDK.AOT.VersionUpdate { public class VersionUpdateHandle { private readonly IVersionUpdate _updateImpl; private readonly IVersionUpdateUI _updateUI; public VersionUpdateHandle(IVersionUpdateUI ui) { #if USE_YOO _updateImpl = new VersionUpdate_YooAsset(ui); #else _updateImpl = new VersionUpdate_Addressables(ui); #endif _updateUI = ui; } public async UniTask CheckUpdate() { Debug.Log("开始检查版本更新"); var checkResult = await _CheckVersion(); switch (checkResult) { case EVersionUpdateType.NoUpdate: Debug.Log("无需更新"); return true; case EVersionUpdateType.ResUpdate: Debug.Log("资源更新"); await _UpdateRes(); return true; default: _updateUI.UpdateProgressText("Start Failed!"); Debug.LogError("暂未实现的更新类型: " + checkResult); return false; } } private async UniTask _CheckVersion() { return await _updateImpl.CheckVersion(); } private async UniTask _UpdateRes() { var versionInfo = _updateImpl.GetVersionInfo(); var totalBytes = versionInfo.totalBytes; var totalMb = totalBytes / 1024f / 1024f; var totalMbStr = totalMb.ToString("F2"); var showStr = $"Find New Version: {versionInfo.newVersion}\n" + $"Current Version: {versionInfo.oldVersion}\n" + $"Need Download Size: {totalMbStr}MB\n" + $"Continue?"; var result = await _updateUI.ShowDialog("Need Update", showStr); if (!result) { return false; } return await _updateImpl.UpdateRes(); } } }