热更系统修改并测试
This commit is contained in:
@@ -27,6 +27,9 @@ public class PatchOperation
|
||||
{
|
||||
this.data = data;
|
||||
PkgVersionKey = $"{Application.productName}_{data.packageName}";
|
||||
#if !UNITY_EDITOR
|
||||
PkgVersionKey = $"Editor_{Application.productName}_{data.packageName}";
|
||||
#endif
|
||||
}
|
||||
#region 初始化相关
|
||||
public async UniTask<bool> InitializePackage()
|
||||
@@ -179,10 +182,15 @@ public class PatchOperation
|
||||
{
|
||||
if (showBox)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}请求版本")
|
||||
.SetContent($"{operation.Error}")
|
||||
.AddButton("退出", (box) => { Application.Quit(); });
|
||||
if(await CheckUseLocalVersion(operation))
|
||||
{
|
||||
string cachedVersion = GetCachedPackageVersion();
|
||||
if (!string.IsNullOrEmpty(cachedVersion))
|
||||
{
|
||||
packageVersion = cachedVersion;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -193,6 +201,24 @@ public class PatchOperation
|
||||
}
|
||||
return operation.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
public async UniTask<bool> CheckUseLocalVersion(RequestPackageVersionOperation operation)
|
||||
{
|
||||
var completionSource = new UniTaskCompletionSource<bool>();
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}请求版本")
|
||||
.SetContent($"{operation.Error}")
|
||||
.AddButton("继续", (box) =>
|
||||
{
|
||||
completionSource.TrySetResult(true);
|
||||
})
|
||||
.AddButton("退出", (box) =>
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
Application.Quit();
|
||||
});
|
||||
bool shouldContinue = await completionSource.Task;
|
||||
return shouldContinue;
|
||||
}
|
||||
public async Task<string> GetBuildinPackageVersion()
|
||||
{
|
||||
var operation = new GetBuildinPackageVersionOperation(data.packageName);
|
||||
@@ -218,10 +244,8 @@ public class PatchOperation
|
||||
|
||||
public void SaveVersionToCache()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
PlayerPrefs.SetString(PkgVersionKey, packageVersion);
|
||||
PlayerPrefs.Save();
|
||||
#endif
|
||||
PatchEvent.UpdateStatus($"更新完成{data.packageName}");
|
||||
Debug.Log($"更新{data.packageName}完成,版本号{packageVersion}");
|
||||
|
||||
@@ -263,21 +287,28 @@ public class PatchOperation
|
||||
var completionSource = new UniTaskCompletionSource<bool>();
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}发现更新")
|
||||
.SetContent($"发现资源更新\n{GetCachedPackageVersion()}=>{packageVersion}: {downloader.TotalDownloadBytes / 1024f / 1024f:F1}MB")
|
||||
.SetContent($"发现资源更新\n{GetCachedPackageVersion()}=>{packageVersion}: {FormatFileSize(downloader.TotalDownloadBytes)}")
|
||||
.AddButton("下载", async (box) =>
|
||||
{
|
||||
bool success = await DownloadPackageFiles();
|
||||
completionSource.TrySetResult(success);
|
||||
})
|
||||
.AddButton("跳过", (box) =>
|
||||
.AddButton("跳过", async (box) =>
|
||||
{
|
||||
downloader.CancelDownload();
|
||||
packageVersion = GetCachedPackageVersion();
|
||||
await UpdatePackageManifest();
|
||||
completionSource.TrySetResult(true);
|
||||
})
|
||||
.AddButton("退出", (box) =>
|
||||
{
|
||||
downloader.CancelDownload();
|
||||
completionSource.TrySetResult(false);
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
});
|
||||
bool shouldContinue = await completionSource.Task;
|
||||
return shouldContinue;
|
||||
@@ -318,5 +349,12 @@ public class PatchOperation
|
||||
}
|
||||
return operation.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
public string FormatFileSize(long size)
|
||||
{
|
||||
if (size < 1024 * 1024)
|
||||
return $"{(size / 1024f):F1}KB";
|
||||
else
|
||||
return $"{size / 1024f / 1024f:F1}MB";
|
||||
}
|
||||
#endregion 下载相关
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user