mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -21,7 +21,7 @@ namespace HotMain.SHGame.Procedure
|
||||
//热更新的dll名称
|
||||
public static readonly string[] HotDllName =
|
||||
{
|
||||
"HotSamples.dll"
|
||||
"HotSamples.dll",
|
||||
};
|
||||
|
||||
public static readonly string[] AotMetaAssemblyFiles =
|
||||
|
@@ -21,11 +21,34 @@ namespace HotMain.SHGame.Procedure
|
||||
|
||||
private async UniTask CreatePackageDownloader(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
|
||||
// 打包时内置在包体内的资源 直接先使用包体资源,实例化 登录加载界面后,再去检查是否需要下载更新
|
||||
//加载AOT
|
||||
await LoadMetadataForAOTAssemblies();
|
||||
|
||||
//加载GameLauncher dll
|
||||
#if !UNITY_EDITOR
|
||||
_launcherAss = await LoadHotfixDll(ProcedureInitializePackage.RawFilePackageName, "GameLauncher.dll");
|
||||
#else
|
||||
_launcherAss = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == "GameLauncher");
|
||||
Log.Warning("加载热更dll:GameLauncher.dll");
|
||||
#endif
|
||||
|
||||
//切换到更新资源版本
|
||||
ChangeState<ProcedurePackageDownloader>(procedureOwner);
|
||||
|
||||
}
|
||||
|
||||
public static async UniTask<Assembly> LoadHotfixDll(string packageName, string name)
|
||||
{
|
||||
Log.Warning($"加载热更dll:{name}");
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
var handle = package.LoadRawFileAsync(name);
|
||||
await handle.ToUniTask();
|
||||
var dllBytes = handle.GetRawFileData();
|
||||
var assembly = Assembly.Load(dllBytes);
|
||||
Log.Warning($"加载热更dll完成:{name}");
|
||||
return assembly;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,10 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SHFrame;
|
||||
using SHFrame.FSM;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using EventArgs = SHFrame.EventArgs;
|
||||
|
||||
namespace HotMain.SHGame.Procedure
|
||||
{
|
||||
@@ -12,27 +15,71 @@ namespace HotMain.SHGame.Procedure
|
||||
|
||||
private int totalDownloadCount = 0;
|
||||
private long totalDownloadBytes = 0;
|
||||
|
||||
private IFsm<IProcedureManager> Procedure;
|
||||
private bool isStartDownloader = false;
|
||||
|
||||
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
|
||||
Procedure = procedureOwner;
|
||||
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
launcherPatchCount = 0;
|
||||
totalDownloadCount = 0;
|
||||
totalDownloadBytes = 0;
|
||||
Download(procedureOwner);
|
||||
|
||||
//监听开始下载
|
||||
EventUtil.AddListener(HotMainEvent.StartDownloader,OnStartDownloader);
|
||||
|
||||
//打开Launcher
|
||||
RunLauncher().Forget();
|
||||
|
||||
}
|
||||
|
||||
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
||||
{
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
|
||||
EventUtil.RemoveListener(HotMainEvent.StartDownloader,OnStartDownloader);
|
||||
}
|
||||
|
||||
public async UniTask RunLauncher()
|
||||
{
|
||||
|
||||
//打开LauncherMain
|
||||
var package = YooAssets.GetPackage(ProcedureInitializePackage.DefaultPackageName);
|
||||
var handle = package.LoadAssetAsync<GameObject>("HotLauncher");
|
||||
await handle.ToUniTask();
|
||||
var hotLauncher = handle.InstantiateSync();
|
||||
hotLauncher.name = $"HotLauncher_{package.GetPackageVersion()}";
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnStartDownloader(EventArgs eventargs)
|
||||
{
|
||||
Download(Procedure);
|
||||
}
|
||||
|
||||
|
||||
private async void Download(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
// //检查launcher标签的资源
|
||||
// launcherPatchCount += TryGetTagPatchCount(ProcedureInitializePackage.RawFilePackageName, YooTag.LAUNCHER);
|
||||
// launcherPatchCount += TryGetTagPatchCount(ProcedureInitializePackage.DefaultPackageName, YooTag.LAUNCHER);
|
||||
//
|
||||
// if (launcherPatchCount > 0)
|
||||
// {
|
||||
// Log.Warning("launcher资源需要更新,下载完成后需要重启游戏");
|
||||
// totalDownloadCount += launcherPatchCount;
|
||||
// }
|
||||
|
||||
if (isStartDownloader) return;
|
||||
|
||||
isStartDownloader = true;
|
||||
|
||||
//检查launcher标签的资源
|
||||
launcherPatchCount += TryGetTagPatchCount(ProcedureInitializePackage.RawFilePackageName, "Launcher");
|
||||
launcherPatchCount += TryGetTagPatchCount(ProcedureInitializePackage.DefaultPackageName, "Launcher");
|
||||
|
||||
if (launcherPatchCount > 0)
|
||||
{
|
||||
Log.Warning("launcher资源需要更新,下载完成后需要重启游戏");
|
||||
totalDownloadCount += launcherPatchCount;
|
||||
}
|
||||
|
||||
// 完全通过远端获取的资源,每次启动游戏都检查是否需要更新
|
||||
//TODO 把这个玩意拆分成 1、获取下载文件大小,2、提示总的下载大小,提示确认,3、开始下载
|
||||
@@ -72,6 +119,7 @@ namespace HotMain.SHGame.Procedure
|
||||
|
||||
//切换到加载热更包入口
|
||||
ChangeState<ProcedureLoadHot>(procedureOwner);
|
||||
|
||||
}
|
||||
|
||||
private int TryGetTagPatchCount(string packageName, string tag)
|
||||
@@ -174,6 +222,7 @@ namespace HotMain.SHGame.Procedure
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnDownloadProgressUpdateFunction(int totalCount, int currentCount, long totalBytes, long currentBytes)
|
||||
{
|
||||
EventUtil.DispatchEvent(HotMainEvent.DownloaderProgressUpdate,totalCount,currentCount,totalBytes,currentBytes);
|
||||
Log.Debug($"文件总数:{totalCount}, 已下载文件数:{currentCount}, 下载总大小:{totalBytes}, 已下载大小:{currentBytes}");
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
@@ -86,4 +87,5 @@ namespace HotMain.SHGame.YooAsset
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user