This commit is contained in:
2025-11-17 10:51:40 +08:00
parent ab52ac7611
commit 98a32d438f
16 changed files with 1372 additions and 62 deletions

View File

@@ -655,7 +655,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
MainCamera: {fileID: 330585545} MainCamera: {fileID: 330585545}
PlayMode: 0 PlayMode: 2
--- !u!4 &1019312449 --- !u!4 &1019312449
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -59,13 +59,20 @@ namespace Tuan.GameFramework
default: default:
break; break;
} }
await initializationOperation.ToUniTask(); await initializationOperation;
if (initializationOperation.Status != EOperationStatus.Succeed) if (initializationOperation.Status != EOperationStatus.Succeed)
{ {
MessageBox.Show() MessageBox.Show()
.SetTitle($"{data.packageName}初始化") .SetTitle($"{data.packageName}初始化")
.SetContent($"{initializationOperation.Error}") .SetContent($"{initializationOperation.Error}")
.AddButton("退出", (box) => { Application.Quit(); }); .AddButton("退出", (box) =>
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
} }
else else
{ {
@@ -178,7 +185,7 @@ namespace Tuan.GameFramework
public async UniTask<bool> RequestPackageVersion(bool showBox = true) public async UniTask<bool> RequestPackageVersion(bool showBox = true)
{ {
var operation = package.RequestPackageVersionAsync(true, 5); var operation = package.RequestPackageVersionAsync(true, 5);
await operation.ToUniTask(); await operation;
if (operation.Status != EOperationStatus.Succeed) if (operation.Status != EOperationStatus.Succeed)
{ {
if (showBox) if (showBox)
@@ -189,6 +196,8 @@ namespace Tuan.GameFramework
if (!string.IsNullOrEmpty(cachedVersion)) if (!string.IsNullOrEmpty(cachedVersion))
{ {
packageVersion = cachedVersion; packageVersion = cachedVersion;
PatchEvent.UpdateStatus($"获取缓存版本成功{data.packageName}");
Debug.Log($"获取缓存版本成功{data.packageName}{packageVersion}");
return true; return true;
} }
} }
@@ -197,8 +206,8 @@ namespace Tuan.GameFramework
else else
{ {
packageVersion = operation.PackageVersion; packageVersion = operation.PackageVersion;
PatchEvent.UpdateStatus($"获取版本成功{data.packageName}"); PatchEvent.UpdateStatus($"获取远端版本成功{data.packageName}");
Debug.Log($"获取版本成功{data.packageName}{packageVersion}"); Debug.Log($"获取远端版本成功{data.packageName}{packageVersion}");
} }
return operation.Status == EOperationStatus.Succeed; return operation.Status == EOperationStatus.Succeed;
} }
@@ -215,7 +224,11 @@ namespace Tuan.GameFramework
.AddButton("退出", (box) => .AddButton("退出", (box) =>
{ {
completionSource.TrySetResult(false); completionSource.TrySetResult(false);
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit(); Application.Quit();
#endif
}); });
bool shouldContinue = await completionSource.Task; bool shouldContinue = await completionSource.Task;
return shouldContinue; return shouldContinue;
@@ -254,7 +267,7 @@ namespace Tuan.GameFramework
public async UniTask<bool> UpdatePackageManifest(bool showBox = true) public async UniTask<bool> UpdatePackageManifest(bool showBox = true)
{ {
var operation = package.UpdatePackageManifestAsync(packageVersion, 10); var operation = package.UpdatePackageManifestAsync(packageVersion, 10);
await operation.ToUniTask(); await operation;
if (operation.Status != EOperationStatus.Succeed) if (operation.Status != EOperationStatus.Succeed)
{ {
if (showBox) if (showBox)
@@ -262,7 +275,14 @@ namespace Tuan.GameFramework
MessageBox.Show() MessageBox.Show()
.SetTitle($"{data.packageName}更新清单") .SetTitle($"{data.packageName}更新清单")
.SetContent($"{operation.Error}") .SetContent($"{operation.Error}")
.AddButton("退出", (box) => { Application.Quit(); }); .AddButton("退出", (box) =>
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
} }
} }
else else
@@ -308,7 +328,7 @@ namespace Tuan.GameFramework
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false; UnityEditor.EditorApplication.isPlaying = false;
#else #else
Application.Quit(); Application.Quit();
#endif #endif
}); });
bool shouldContinue = await completionSource.Task; bool shouldContinue = await completionSource.Task;
@@ -320,7 +340,7 @@ namespace Tuan.GameFramework
return true; return true;
Debug.Log($"{data.packageName} DownloadPackageFiles {downloader.TotalDownloadCount}"); Debug.Log($"{data.packageName} DownloadPackageFiles {downloader.TotalDownloadCount}");
downloader.BeginDownload(); downloader.BeginDownload();
await downloader.ToUniTask(); await downloader;
if (downloader.Status != EOperationStatus.Succeed) if (downloader.Status != EOperationStatus.Succeed)
{ {
if (showBox) if (showBox)
@@ -328,7 +348,14 @@ namespace Tuan.GameFramework
MessageBox.Show() MessageBox.Show()
.SetTitle($"{data.packageName}下载文件") .SetTitle($"{data.packageName}下载文件")
.SetContent($"{downloader.Error}") .SetContent($"{downloader.Error}")
.AddButton("退出", (box) => { Application.Quit(); }); .AddButton("退出", (box) =>
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
} }
return false; return false;
} }
@@ -337,7 +364,7 @@ namespace Tuan.GameFramework
public async UniTask<bool> ClearCacheBundle(bool showBox = true) public async UniTask<bool> ClearCacheBundle(bool showBox = true)
{ {
var operation = package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles); var operation = package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles);
await operation.ToUniTask(); await operation;
if (operation.Status != EOperationStatus.Succeed) if (operation.Status != EOperationStatus.Succeed)
{ {
if (showBox) if (showBox)
@@ -345,7 +372,14 @@ namespace Tuan.GameFramework
MessageBox.Show() MessageBox.Show()
.SetTitle($"{data.packageName}清除缓存") .SetTitle($"{data.packageName}清除缓存")
.SetContent($"{operation.Error}") .SetContent($"{operation.Error}")
.AddButton("退出", (box) => { Application.Quit(); }); .AddButton("退出", (box) =>
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
} }
} }
return operation.Status == EOperationStatus.Succeed; return operation.Status == EOperationStatus.Succeed;

View File

@@ -22,52 +22,33 @@ namespace Tuan.GameFramework
} }
public async UniTask Execute() public async UniTask Execute()
{ {
#if !UNITY_EDITOR
CheckIsOffline();
#endif
if (!await operation.InitializePackage()) return; if (!await operation.InitializePackage()) return;
var version = await GetBestPackageVersion(); if (!await operation.RequestPackageVersion())
#if UNITY_EDITOR {
if (!await operation.RequestPackageVersion()) return; operation.packageVersion = await operation.GetBuildinPackageVersion();
version = operation.packageVersion; }
#endif
//获取版本失败 //获取版本失败
if (version == null) if (operation.packageVersion == null)
{ {
MessageBox.Show() MessageBox.Show()
.SetTitle($"{operation.data.packageName}获取版本") .SetTitle($"{operation.data.packageName}获取版本")
.SetContent("获取版本失败") .SetContent("获取版本失败")
.AddButton("退出", (box) => { Application.Quit(); }); .AddButton("退出", (box) =>
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
return; return;
} }
operation.packageVersion = version;
if (!await operation.UpdatePackageManifest()) return; if (!await operation.UpdatePackageManifest()) return;
await HotDllLoader.Inst.LoadDll(YooAssets.GetPackage("Preload"), "GameScripts.Preload"); await HotDllLoader.Inst.LoadDll(YooAssets.GetPackage("Preload"), "GameScripts.Preload");
await LoadAndShowPatchWindow(); await LoadAndShowPatchWindow();
MainUICanvas.Inst.InitBg.SetActive(false); MainUICanvas.Inst.InitBg.SetActive(false);
_ = UpdatePreloadPackage(); _ = UpdatePreloadPackage();
} }
void CheckIsOffline()
{
if (string.IsNullOrEmpty(operation.GetCachedPackageVersion()))
{
operation.data.playMode = EPlayMode.OfflinePlayMode;
}
}
async Task<string> GetBestPackageVersion()
{
string cachedVersion = operation.GetCachedPackageVersion();
if (!string.IsNullOrEmpty(cachedVersion))
{
return cachedVersion;
}
string buildinVersion = await operation.GetBuildinPackageVersion();
if (!string.IsNullOrEmpty(buildinVersion))
{
return buildinVersion;
}
return null;
}
private async UniTask LoadAndShowPatchWindow() private async UniTask LoadAndShowPatchWindow()
{ {
var assetHandle = operation.package.LoadAssetAsync<GameObject>("PatchWindow"); var assetHandle = operation.package.LoadAssetAsync<GameObject>("PatchWindow");
@@ -82,9 +63,9 @@ namespace Tuan.GameFramework
if (!await operation.UpdatePackageManifest(false)) return; if (!await operation.UpdatePackageManifest(false)) return;
if (operation.CreateDownloader()) if (operation.CreateDownloader())
{ {
if (!await operation.DownloadPackageFiles()) return; if (!await operation.DownloadPackageFiles(false)) return;
} }
if (!await operation.ClearCacheBundle()) return; if (!await operation.ClearCacheBundle(false)) return;
operation.SaveVersionToCache(); operation.SaveVersionToCache();
} }
} }

View File

@@ -1,10 +1,10 @@
{ {
"FileVersion": "1.0.0", "FileVersion": "1.0.0",
"PackageName": "Preload", "PackageName": "Preload",
"PackageVersion": "2025-11-12-1073", "PackageVersion": "2025-11-17-627",
"Wrappers": [ "Wrappers": [
{ {
"BundleGUID": "b3d4761368f31213b75688ef3b1d4b9e", "BundleGUID": "982976656ae12abc351fdc9e9a2fdb42",
"FileName": "preload_assets_gameres_preload_hotupdatedll.bundle" "FileName": "preload_assets_gameres_preload_hotupdatedll.bundle"
}, },
{ {

View File

@@ -1 +1 @@
2025-11-12-1073 2025-11-17-627

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6bb98d3e5ae4c2a4c9d08a710d6aa4c6 guid: 840f398ea6784d94a8a61fef019fcb63
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:

View File

@@ -0,0 +1 @@
461ea148

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 0389d7879276f2a4b88693887ea07df8 guid: 694d1443dd56f864bb1f9dae8a87d4cd
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:

File diff suppressed because one or more lines are too long