67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
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<bool> 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<EVersionUpdateType> _CheckVersion()
|
|
{
|
|
return await _updateImpl.CheckVersion();
|
|
}
|
|
|
|
private async UniTask<bool> _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();
|
|
}
|
|
|
|
}
|
|
}
|