热更流程完成

This commit is contained in:
2025-11-03 17:46:28 +08:00
parent 75fb982872
commit db6f5d147e
43 changed files with 2596 additions and 326 deletions

View File

@@ -1,4 +1,4 @@
using UnityEditor;
using UnityEditor;
using UnityEngine;
using YooAsset.Editor;
using YooAsset;

View File

@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
@@ -43,7 +43,7 @@ public class CopyHotDll
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/AssembliesPostIl2CppStrip/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/";
string destDir = $"{Application.dataPath}/GameRes/Main/HotUpdateDll/";
foreach (string dll in Boot.Inst.DepDlls)
foreach (string dll in HotDllLoader.Inst.DepDlls)
{
string sourcePath = $"{sourceDir}/{dll}";
string destPath = $"{destDir}/{dll}.bytes";

View File

@@ -1,18 +1,14 @@
using Cysharp.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
public class Boot : SingletonMono<Boot>
public class Boot : MonoBehaviour
{
public List<string> DepDlls = new List<string>()
{
"mscorlib.dll",
"System.dll",
"System.Core.dll",
"Mirror.dll"
};
public GameObject MainUICanvas;
public Camera UICamera;
public Camera MainCamera;
public EPlayMode PlayMode = EPlayMode.EditorSimulateMode;
void Awake()
{
@@ -21,6 +17,9 @@ public class Boot : SingletonMono<Boot>
#endif
Application.targetFrameRate = 60;
Application.runInBackground = true;
DontDestroyOnLoad(MainUICanvas);
DontDestroyOnLoad(UICamera);
DontDestroyOnLoad(MainCamera);
}
async void Start()
{
@@ -28,10 +27,14 @@ public class Boot : SingletonMono<Boot>
GameManager.Inst.MainUICanvas = MainUICanvas;
bool updateSuccess = await PatchManager.Inst.StartOperation(PlayMode);
if (updateSuccess)
EnterGame();
await EnterGame();
}
private void EnterGame()
private async UniTask EnterGame()
{
Debug.Log("EnterGame");
var assetHandle = YooAssets.TryGetPackage("Main").LoadSceneAsync("Test");
await assetHandle.ToUniTask();
if (assetHandle.Status == EOperationStatus.Succeed)
assetHandle.ActivateScene();
}
}

View File

@@ -1,3 +1,4 @@
using Cysharp.Threading.Tasks;
using HybridCLR;
using System.Collections.Generic;
using System.Linq;
@@ -7,26 +8,34 @@ using YooAsset;
public class HotDllLoader : Singleton<HotDllLoader>
{
public void LoadDll(ResourcePackage package, string dll)
public List<string> DepDlls = new List<string>()
{
"mscorlib.dll",
"System.dll",
"System.Core.dll",
};
public async UniTask LoadDll(ResourcePackage package, string dll)
{
if (package.GetAssetInfo(dll).Error == string.Empty)
{
AssetHandle handle = package.LoadAssetSync<TextAsset>(dll);
AssetHandle handle = package.LoadAssetAsync<TextAsset>(dll);
await handle.ToUniTask();
#if UNITY_EDITOR
Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == dll.Replace(".dll", ""));
#else
Assembly hotUpdateAss = Assembly.Load((handle.AssetObject as TextAsset).bytes);
#endif
Debug.Log($"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{dll}");
Debug.Log($"加载{dll}");
}
}
public void LoadDepDll(ResourcePackage package, List<string> dlls)
public async UniTask LoadDepDll(ResourcePackage package)
{
foreach (string dll in dlls)
foreach (string dll in DepDlls)
{
if (package.GetAssetInfo(dll).Error == string.Empty)
{
AssetHandle handle = package.LoadAssetSync<TextAsset>(dll);
AssetHandle handle = package.LoadAssetAsync<TextAsset>(dll);
await handle.ToUniTask();
RuntimeApi.LoadMetadataForAOTAssembly((handle.AssetObject as TextAsset).bytes, HomologousImageMode.SuperSet);
}
}

View File

@@ -26,122 +26,38 @@ public class MainOperation
public async UniTask Execute()
{
PatchEvent.UpdateProgress(0f);
InitializationOperation initializationOperation = await operation.InitializePackage();
//<2F><>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
if (initializationOperation.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"{initializationOperation.Error}")
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return;
}
PatchEvent.UpdateStatus($"<22><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
Debug.Log($"<22><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
var PackageVersionOperation = await operation.RequestPackageVersion();
if (PackageVersionOperation.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"{PackageVersionOperation.Error}")
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return;
}
operation.packageVersion = PackageVersionOperation.PackageVersion;
PatchEvent.UpdateStatus($"<22><>ȡ<EFBFBD><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
Debug.Log($"<22><>ȡ<EFBFBD><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}<7D><>{operation.packageVersion}");
var PackageManifestOperation = await operation.UpdatePackageManifest();
if (PackageManifestOperation.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"{PackageManifestOperation.Error}")
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return;
}
var DownloaderOperation = operation.CreateDownloader();
if (DownloaderOperation.TotalDownloadCount == 0)
{
operation.SaveVersionToCache();
PatchEvent.UpdateStatus($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{operation.data.packageName}");
Debug.Log($"<22><><EFBFBD><EFBFBD>{operation.data.packageName}<7D><><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><E6B1BE>{operation.packageVersion}");
return;
}
else
if (!await operation.InitializePackage()) return;
if (!await operation.RequestPackageVersion()) return;
if (!await operation.UpdatePackageManifest()) return;
if (operation.CreateDownloader())
{
if (autoDownload)
{
if (!await Download(DownloaderOperation)) return;
if (!await operation.DownloadPackageFiles()) return;
}
else
{
var completionSource = new UniTaskCompletionSource<bool>();
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>\n{operation.GetCachedPackageVersion()}=>{operation.packageVersion}: {DownloaderOperation.TotalDownloadBytes / 1024f / 1024f:F1}MB")
.AddButton("<22><><EFBFBD><EFBFBD>", async (box) =>
{
bool success = await Download(DownloaderOperation);
completionSource.TrySetResult(success);
})
.AddButton("<22><><EFBFBD><EFBFBD>", (box) =>
{
DownloaderOperation.CancelDownload();
completionSource.TrySetResult(true);
})
.AddButton("<22>˳<EFBFBD>", (box) =>
{
completionSource.TrySetResult(false);
Application.Quit();
});
bool shouldContinue = await completionSource.Task;
if (!shouldContinue) return;
if (!await operation.CheckDownloadOrSkip()) return;
}
var ClearCacheFilesOperation = await operation.ClearCacheBundle();
if (ClearCacheFilesOperation.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"{ClearCacheFilesOperation.Error}")
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return;
}
operation.SaveVersionToCache();
PatchEvent.UpdateStatus($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{operation.data.packageName}");
Debug.Log($"<22><><EFBFBD><EFBFBD>{operation.data.packageName}<7D><><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><E6B1BE>{operation.packageVersion}");
}
}
public async UniTask<bool> Download(DownloaderOperation downloaderOperation)
{
if (!await operation.DownloadPackageFiles())
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"{downloaderOperation.Error}")
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return false;
}
return true;
if (!await operation.ClearCacheBundle()) return;
operation.SaveVersionToCache();
}
private void OnDownloadUpdate(DownloadUpdateData downloadUpdateData)
{
float progress = (float)downloadUpdateData.CurrentDownloadBytes / downloadUpdateData.TotalDownloadBytes;
string sizeText = $"{(downloadUpdateData.CurrentDownloadBytes / 1024f / 1024f):F1}MB / {(downloadUpdateData.TotalDownloadBytes / 1024f / 1024f):F1}MB";
PatchEvent.UpdateProgress(progress);
PatchEvent.UpdateDownloadSize(sizeText);
PatchEvent.UpdateStatus($"{data.packageName} <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
PatchEvent.UpdateStatus($"{data.packageName} 资源下载中...");
}
private void OnDownloadFinish(DownloaderFinishData downloaderFinishData)
{
PatchEvent.UpdateStatus("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
PatchEvent.UpdateStatus("下载完成");
}
private void OnDownloadError(DownloadErrorData downloadErrorData)
{
PatchEvent.UpdateStatus($"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>:{downloadErrorData.FileName}\n{downloadErrorData.ErrorInfo}");
PatchEvent.UpdateStatus($"下载失败:{downloadErrorData.FileName}\n{downloadErrorData.ErrorInfo}");
}
}

View File

@@ -11,6 +11,8 @@ public class PatchManager : Singleton<PatchManager>
MainOperation _mainOperation = new MainOperation(playMode);
await _mainOperation.Execute();
await HotDllLoader.Inst.LoadDepDll(YooAssets.GetPackage("Main"));
await HotDllLoader.Inst.LoadDll(YooAssets.GetPackage("Main"), "GameScripts.Main");
return true;
}

View File

@@ -28,8 +28,8 @@ public class PatchOperation
this.data = data;
PkgVersionKey = $"{Application.productName}_{data.packageName}";
}
#region <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public async UniTask<InitializationOperation> InitializePackage()
#region
public async UniTask<bool> InitializePackage()
{
package = YooAssets.TryGetPackage(data.packageName);
if (package == null)
@@ -56,7 +56,19 @@ public class PatchOperation
break;
}
await initializationOperation.ToUniTask();
return initializationOperation;
if (initializationOperation.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle($"{data.packageName}初始化")
.SetContent($"{initializationOperation.Error}")
.AddButton("退出", (box) => { Application.Quit(); });
}
else
{
PatchEvent.UpdateStatus($"初始化成功{data.packageName}");
Debug.Log($"初始化成功{data.packageName}");
}
return initializationOperation.Status == EOperationStatus.Succeed;
}
private InitializationOperation InitializeEditorMode(ResourcePackage package)
{
@@ -79,14 +91,14 @@ public class PatchOperation
FileSystemParameters buildinFileSystemParams = null;
if (data.useBuildinFileSystem)
{
// ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>COPY_BUILDIN_PACKAGE_MANIFEST<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>򿽱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɳ<EFBFBD><EFBFBD>Ŀ¼
// 注意:设置参数COPY_BUILDIN_PACKAGE_MANIFEST,可以初始化的时候拷贝内置清单到沙盒目录
buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
}
string defaultHostServer = GetHostServerURL();
string fallbackHostServer = GetHostServerURL();
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
// ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>INSTALL_CLEAR_MODE<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>װ<EFBFBD><EFBFBD>ʱ<EFBFBD>򽫿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 注意:设置参数INSTALL_CLEAR_MODE,可以解决覆盖安装的时候将拷贝的内置清单文件清理的问题。
var cacheFileSystemParams = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
cacheFileSystemParams.AddParameter(FileSystemParametersDefine.INSTALL_CLEAR_MODE, EOverwriteInstallClearMode.ClearAllManifestFiles);
@@ -102,7 +114,7 @@ public class PatchOperation
var createParameters = new WebPlayModeParameters();
string defaultHostServer = GetHostServerURL();
string fallbackHostServer = GetHostServerURL();
string packageRoot = $"{WeChatWASM.WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE"; //ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸Ĵ˴<EFBFBD><EFBFBD><EFBFBD>
string packageRoot = $"{WeChatWASM.WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE"; //注意:如果有子目录,请修改此处!
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
createParameters.WebServerFileSystemParameters = WechatFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteServices);
return package.InitializeAsync(createParameters);
@@ -157,13 +169,29 @@ public class PatchOperation
return $"{_fallbackHostServer}/{fileName}";
}
}
#endregion <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public async UniTask<RequestPackageVersionOperation> RequestPackageVersion()
#endregion
#region
public async UniTask<bool> RequestPackageVersion(bool showBox = true)
{
var operation = package.RequestPackageVersionAsync(true, 1);
var operation = package.RequestPackageVersionAsync(true, 5);
await operation.ToUniTask();
return operation;
if (operation.Status != EOperationStatus.Succeed)
{
if (showBox)
{
MessageBox.Show()
.SetTitle($"{data.packageName}请求版本")
.SetContent($"{operation.Error}")
.AddButton("退出", (box) => { Application.Quit(); });
}
}
else
{
packageVersion = operation.PackageVersion;
PatchEvent.UpdateStatus($"获取版本成功{data.packageName}");
Debug.Log($"获取版本成功{data.packageName}{packageVersion}");
}
return operation.Status == EOperationStatus.Succeed;
}
public async Task<string> GetBuildinPackageVersion()
{
@@ -194,37 +222,101 @@ public class PatchOperation
PlayerPrefs.SetString(PkgVersionKey, packageVersion);
PlayerPrefs.Save();
#endif
PatchEvent.UpdateStatus($"更新完成{data.packageName}");
Debug.Log($"更新{data.packageName}完成,版本号{packageVersion}");
}
public async UniTask<UpdatePackageManifestOperation> UpdatePackageManifest()
public async UniTask<bool> UpdatePackageManifest(bool showBox = true)
{
var operation = package.UpdatePackageManifestAsync(packageVersion,5);
var operation = package.UpdatePackageManifestAsync(packageVersion,10);
await operation.ToUniTask();
return operation;
if (operation.Status != EOperationStatus.Succeed)
{
if (showBox)
{
MessageBox.Show()
.SetTitle($"{data.packageName}更新清单")
.SetContent($"{operation.Error}")
.AddButton("退出", (box) => { Application.Quit(); });
}
}
else
{
PatchEvent.UpdateStatus($"获取资源清单成功{data.packageName}");
Debug.Log($"获取资源清单成功{data.packageName}");
}
return operation.Status == EOperationStatus.Succeed;
}
#endregion <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public ResourceDownloaderOperation CreateDownloader()
#endregion
#region
public bool CreateDownloader()
{
downloader = package.CreateResourceDownloader(data.downloadingMaxNum, data.failedTryAgain);
downloader.DownloadErrorCallback = data.downloadError;
downloader.DownloadFinishCallback = data.downloadFinish;
downloader.DownloadUpdateCallback = data.downloadUpdate;
return downloader;
if (downloader.TotalDownloadCount == 0) return false;
return true;
}
public async UniTask<bool> DownloadPackageFiles()
public async UniTask<bool> CheckDownloadOrSkip()
{
var completionSource = new UniTaskCompletionSource<bool>();
MessageBox.Show()
.SetTitle($"{data.packageName}发现更新")
.SetContent($"发现资源更新\n{GetCachedPackageVersion()}=>{packageVersion}: {downloader.TotalDownloadBytes / 1024f / 1024f:F1}MB")
.AddButton("下载", async (box) =>
{
bool success = await DownloadPackageFiles();
completionSource.TrySetResult(success);
})
.AddButton("跳过", (box) =>
{
downloader.CancelDownload();
completionSource.TrySetResult(true);
})
.AddButton("退出", (box) =>
{
completionSource.TrySetResult(false);
Application.Quit();
});
bool shouldContinue = await completionSource.Task;
return shouldContinue;
}
public async UniTask<bool> DownloadPackageFiles(bool showBox = true)
{
if (downloader.TotalDownloadCount == 0)
return true;
Debug.Log($"{data.packageName} DownloadPackageFiles {downloader.TotalDownloadCount}");
downloader.BeginDownload();
await downloader.ToUniTask();
if (downloader.Status != EOperationStatus.Succeed)
{
if (showBox)
{
MessageBox.Show()
.SetTitle($"{data.packageName}下载文件")
.SetContent($"{downloader.Error}")
.AddButton("退出", (box) => { Application.Quit(); });
}
return false;
}
return downloader.Status == EOperationStatus.Succeed;
}
public async UniTask<ClearCacheFilesOperation> ClearCacheBundle()
public async UniTask<bool> ClearCacheBundle(bool showBox = true)
{
var operation = package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles);
await operation.ToUniTask();
return operation;
if (operation.Status != EOperationStatus.Succeed)
{
if (showBox)
{
MessageBox.Show()
.SetTitle($"{data.packageName}清除缓存")
.SetContent($"{operation.Error}")
.AddButton("退出", (box) => { Application.Quit(); });
}
}
return operation.Status == EOperationStatus.Succeed;
}
#endregion <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endregion
}

View File

@@ -23,46 +23,27 @@ public class PreloadOperation
#if !UNITY_EDITOR
CheckIsOffline();
#endif
InitializationOperation initializationOperation = await operation.InitializePackage();
//<2F><>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
if (initializationOperation.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent($"{initializationOperation.Error}")
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return;
}
Debug.Log($"<22><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
if (!await operation.InitializePackage()) return;
var version = await GetBestPackageVersion();
#if UNITY_EDITOR
var PackageVersionOperation = await operation.RequestPackageVersion();
version = PackageVersionOperation.PackageVersion;
if (!await operation.RequestPackageVersion()) return;
version = operation.packageVersion;
#endif
//<EFBFBD><EFBFBD>ȡ<EFBFBD>汾ʧ<EFBFBD><EFBFBD>
//获取版本失败
if (version == null)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent("<EFBFBD><EFBFBD>ȡ<EFBFBD>汾ʧ<EFBFBD><EFBFBD>")
.AddButton("<EFBFBD>˳<EFBFBD>", (box) => { Application.Quit(); });
.SetTitle($"{operation.data.packageName}获取版本")
.SetContent("获取版本失败")
.AddButton("退出", (box) => { Application.Quit(); });
return;
}
operation.packageVersion = version;
Debug.Log($"<22><>ȡ<EFBFBD><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}<7D><>{version}");
UpdatePackageManifestOperation updatePackageManifest = await operation.UpdatePackageManifest();
//<2F><>ȡ<EFBFBD><C8A1>Դ<EFBFBD>嵥ʧ<E5B5A5><CAA7>
if (updatePackageManifest.Status != EOperationStatus.Succeed)
{
MessageBox.Show()
.SetTitle(operation.data.packageName)
.SetContent(updatePackageManifest.Error)
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
return;
}
if (!await operation.UpdatePackageManifest()) return;
await HotDllLoader.Inst.LoadDll(YooAssets.GetPackage("Preload"), "GameScripts.Preload");
await LoadAndShowPatchWindow();
GameManager.Inst.MainUICanvas.transform.Find("InitBg").gameObject.SetActive(false);
_ = UpdatePreloadPackage();
}
void CheckIsOffline()
{
@@ -91,41 +72,17 @@ public class PreloadOperation
await assetHandle.ToUniTask();
if (assetHandle.Status == EOperationStatus.Succeed)
GameObject.Instantiate(assetHandle.AssetObject, GameManager.Inst.MainUICanvas.transform);
Debug.Log("创建热更信息界面");
}
private async UniTask UpdatePreloadPackage()
{
var PackageVersionOperation = await operation.RequestPackageVersion();
if (PackageVersionOperation.Status != EOperationStatus.Succeed)
if (!await operation.RequestPackageVersion(false)) return;
if (!await operation.UpdatePackageManifest(false)) return;
if (operation.CreateDownloader())
{
Debug.Log($"{operation.data.packageName}<7D><>̨<EFBFBD><CCA8><EFBFBD>°汾ʧ<E6B1BE>ܣ<EFBFBD>{PackageVersionOperation.Error}");
return;
}
operation.packageVersion = PackageVersionOperation.PackageVersion;
var PackageManifestOperation = await operation.UpdatePackageManifest();
if (PackageManifestOperation.Status != EOperationStatus.Succeed)
{
Debug.Log($"{operation.data.packageName}<7D><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>嵥ʧ<E5B5A5>ܣ<EFBFBD>{PackageManifestOperation.Error}");
return;
}
var DownloaderOperation = operation.CreateDownloader();
if(DownloaderOperation.TotalDownloadCount == 0)
{
operation.SaveVersionToCache();
Debug.Log($"<22><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>{operation.data.packageName}<7D><><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><E6B1BE>{operation.packageVersion}");
return;
}
if (!await operation.DownloadPackageFiles())
{
Debug.Log($"{operation.data.packageName}<7D><>̨<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>");
return;
}
var ClearCacheFilesOperation = await operation.ClearCacheBundle();
if (ClearCacheFilesOperation.Status != EOperationStatus.Succeed)
{
Debug.Log($"{operation.data.packageName}<7D><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>δʹ<CEB4>û<EFBFBD><C3BB><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>{ClearCacheFilesOperation.Error}");
return;
if (!await operation.DownloadPackageFiles()) return;
}
if (!await operation.ClearCacheBundle()) return;
operation.SaveVersionToCache();
Debug.Log($"<22><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>{operation.data.packageName}<7D><><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><E6B1BE>{operation.packageVersion}");
}
}