111
This commit is contained in:
34
Assets/GameFramework/Runtime/PatchLogic/HotDllLoader.cs
Normal file
34
Assets/GameFramework/Runtime/PatchLogic/HotDllLoader.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using HybridCLR;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class HotDllLoader : Singleton<HotDllLoader>
|
||||
{
|
||||
public void LoadDll(ResourcePackage package, string dll)
|
||||
{
|
||||
if (package.GetAssetInfo(dll).Error == string.Empty)
|
||||
{
|
||||
AssetHandle handle = package.LoadAssetSync<TextAsset>(dll);
|
||||
#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($"<22><><EFBFBD><EFBFBD>{dll}");
|
||||
}
|
||||
}
|
||||
public void LoadDepDll(ResourcePackage package, List<string> dlls)
|
||||
{
|
||||
foreach (string dll in dlls)
|
||||
{
|
||||
if (package.GetAssetInfo(dll).Error == string.Empty)
|
||||
{
|
||||
AssetHandle handle = package.LoadAssetSync<TextAsset>(dll);
|
||||
RuntimeApi.LoadMetadataForAOTAssembly((handle.AssetObject as TextAsset).bytes, HomologousImageMode.SuperSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 913490bf1a0079744825742899c17961
|
||||
@@ -1,4 +1,5 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
@@ -6,7 +7,8 @@ public class MainOperation
|
||||
{
|
||||
PatchOperationData data;
|
||||
PatchOperation operation;
|
||||
public MainOperation(EPlayMode playMode)
|
||||
bool autoDownload;
|
||||
public MainOperation(EPlayMode playMode, bool autoDownload = false)
|
||||
{
|
||||
data = new PatchOperationData();
|
||||
data.packageName = "Main";
|
||||
@@ -14,12 +16,18 @@ public class MainOperation
|
||||
data.useBuildinFileSystem = false;
|
||||
data.downloadingMaxNum = 10;
|
||||
data.failedTryAgain = 3;
|
||||
data.downloadUpdate = OnDownloadUpdate;
|
||||
data.downloadFinish = OnDownloadFinish;
|
||||
data.downloadError = OnDownloadError;
|
||||
|
||||
operation = new PatchOperation(data);
|
||||
this.autoDownload = autoDownload;
|
||||
}
|
||||
|
||||
public async UniTask Execute()
|
||||
{
|
||||
|
||||
PatchEvent.UpdateProgress(0f);
|
||||
InitializationOperation initializationOperation = await operation.InitializePackage();
|
||||
//<2F><>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
|
||||
if (initializationOperation.Status != EOperationStatus.Succeed)
|
||||
@@ -30,6 +38,8 @@ public class MainOperation
|
||||
.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)
|
||||
{
|
||||
@@ -40,6 +50,8 @@ public class MainOperation
|
||||
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)
|
||||
{
|
||||
@@ -53,25 +65,83 @@ public class MainOperation
|
||||
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 (autoDownload)
|
||||
{
|
||||
if (!await Download(DownloaderOperation)) 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;
|
||||
}
|
||||
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}")
|
||||
.SetContent($"{downloaderOperation.Error}")
|
||||
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
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} <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
|
||||
}
|
||||
|
||||
private void OnDownloadFinish(DownloaderFinishData downloaderFinishData)
|
||||
{
|
||||
PatchEvent.UpdateStatus("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
private void OnDownloadError(DownloadErrorData downloadErrorData)
|
||||
{
|
||||
PatchEvent.UpdateStatus($"<22><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>:{downloadErrorData.FileName}\n{downloadErrorData.ErrorInfo}");
|
||||
}
|
||||
}
|
||||
|
||||
24
Assets/GameFramework/Runtime/PatchLogic/PatchEvent.cs
Normal file
24
Assets/GameFramework/Runtime/PatchLogic/PatchEvent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public static class PatchEvent
|
||||
{
|
||||
public static event Action<string> OnStatusUpdate;
|
||||
public static event Action<float> OnProgressUpdate;
|
||||
public static event Action<string> OnDownloadSizeUpdate;
|
||||
|
||||
public static void UpdateStatus(string status)
|
||||
{
|
||||
OnStatusUpdate?.Invoke(status);
|
||||
}
|
||||
|
||||
public static void UpdateProgress(float progress)
|
||||
{
|
||||
OnProgressUpdate?.Invoke(progress);
|
||||
}
|
||||
|
||||
public static void UpdateDownloadSize(string sizeText)
|
||||
{
|
||||
OnDownloadSizeUpdate?.Invoke(sizeText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e733509362b9e5445b0354a734ec8c10
|
||||
Reference in New Issue
Block a user