72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
|
|
namespace Tuan.GameFramework
|
|
{
|
|
public class PreloadOperation
|
|
{
|
|
PatchOperationData data;
|
|
PatchOperation operation;
|
|
public PreloadOperation(EPlayMode playMode)
|
|
{
|
|
data = new PatchOperationData();
|
|
data.packageName = "Preload";
|
|
data.playMode = playMode;
|
|
data.useBuildinFileSystem = true;
|
|
data.downloadingMaxNum = 10;
|
|
data.failedTryAgain = 3;
|
|
|
|
operation = new PatchOperation(data);
|
|
}
|
|
public async UniTask Execute()
|
|
{
|
|
if (!await operation.InitializePackage()) return;
|
|
if (!await operation.RequestPackageVersion())
|
|
{
|
|
operation.packageVersion = await operation.GetBuildinPackageVersion();
|
|
}
|
|
//获取版本失败
|
|
if (operation.packageVersion == null)
|
|
{
|
|
MessageBox.Show()
|
|
.SetTitle($"{operation.data.packageName}获取版本")
|
|
.SetContent("获取版本失败")
|
|
.AddButton("退出", (box) =>
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
});
|
|
return;
|
|
}
|
|
if (!await operation.UpdatePackageManifest()) return;
|
|
await HotDllLoader.Inst.LoadDll(YooAssets.GetPackage("Preload"), "GameScripts.Preload");
|
|
await LoadAndShowPatchWindow();
|
|
MainUICanvas.Inst.InitBg.SetActive(false);
|
|
_ = UpdatePreloadPackage();
|
|
}
|
|
private async UniTask LoadAndShowPatchWindow()
|
|
{
|
|
var assetHandle = operation.package.LoadAssetAsync<GameObject>("PatchWindow");
|
|
await assetHandle.ToUniTask();
|
|
if (assetHandle.Status == EOperationStatus.Succeed)
|
|
GameObject.Instantiate(assetHandle.AssetObject, MainUICanvas.Inst.Medium);
|
|
Debug.Log("创建热更信息界面");
|
|
}
|
|
private async UniTask UpdatePreloadPackage()
|
|
{
|
|
if (!await operation.RequestPackageVersion(false)) return;
|
|
if (!await operation.UpdatePackageManifest(false)) return;
|
|
if (operation.CreateDownloader())
|
|
{
|
|
if (!await operation.DownloadPackageFiles(false)) return;
|
|
}
|
|
if (!await operation.ClearCacheBundle(false)) return;
|
|
operation.SaveVersionToCache();
|
|
}
|
|
}
|
|
} |