Skip to content

Commit 9473561

Browse files
committed
refactor(launcher): 迁移应用层启动流程到 Startup 包架构
将启动流程从旧的 Procedure/PatchUpdater 体系切换到 com.gameframex.unity.startup 包: - 删除 Procedure/PatchUpdater/* 等老启动状态文件 - 新增 Startup/ApplicationStartupEntry MonoBehaviour 入口 - 新增 ApplicationStartupUIHandler、ApplicationHotfixLauncher 适配器 - 改造 HotfixHelper、LauncherUIHandler 适配新接口 - 更新 Launcher 场景绑定新启动入口
1 parent 3797e35 commit 9473561

37 files changed

Lines changed: 618 additions & 857 deletions

Assets/Scenes/Launcher.unity

Lines changed: 86 additions & 45 deletions
Large diffs are not rendered by default.

Assets/Scripts/Framework/FairyGuiExtensionLoader.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
using System.Collections.Generic;
77
using UnityEngine;
88

9-
namespace Unity.Startup.Procedure
9+
namespace GameFrameX.Startup.Application
1010
{
11+
/// <summary>
12+
/// FairyGUI 扩展加载器,用于加载网络图片、包内资源或本地文件的图片纹理。
13+
/// </summary>
14+
/// <remarks>
15+
/// FairyGUI extension loader used to load texture from network URL, package asset, or local file.
16+
/// </remarks>
1117
public sealed class FairyGuiExtensionLoader : GLoader
1218
{
1319
private static ImageCacheComponent _imageCacheComponent;
@@ -28,6 +34,13 @@ public LoaderItem(string key, NTexture texture, AssetHandle assetHandle = defaul
2834

2935
private readonly Dictionary<string, LoaderItem> _cache = new Dictionary<string, LoaderItem>();
3036

37+
/// <summary>
38+
/// 释放外部加载的纹理资源。
39+
/// </summary>
40+
/// <remarks>
41+
/// Release the externally loaded texture resource.
42+
/// </remarks>
43+
/// <param name="nTexture">要释放的纹理对象 / The texture object to release</param>
3144
protected override void FreeExternal(NTexture nTexture)
3245
{
3346
foreach (var loaderItem in _cache)
@@ -44,6 +57,12 @@ protected override void FreeExternal(NTexture nTexture)
4457
base.FreeExternal(nTexture);
4558
}
4659

60+
/// <summary>
61+
/// 异步加载外部纹理资源。
62+
/// </summary>
63+
/// <remarks>
64+
/// Asynchronously load an external texture resource.
65+
/// </remarks>
4766
protected override async void LoadExternal()
4867
{
4968
if (url.IsNullOrWhiteSpace())
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Cysharp.Threading.Tasks;
2+
using GameFrameX.Startup.Runtime;
3+
4+
namespace GameFrameX.Startup.Application
5+
{
6+
/// <summary>
7+
/// 应用层热更启动器,将 <see cref="HotfixHelper"/> 适配到 <see cref="IHotfixLauncher"/> 接口。
8+
/// </summary>
9+
/// <remarks>
10+
/// Application hotfix launcher that adapts <see cref="HotfixHelper"/> to the <see cref="IHotfixLauncher"/> interface.
11+
/// </remarks>
12+
public sealed class ApplicationHotfixLauncher : IHotfixLauncher
13+
{
14+
/// <summary>
15+
/// 异步启动热更程序集。
16+
/// </summary>
17+
/// <remarks>
18+
/// Asynchronously start the hotfix assembly.
19+
/// </remarks>
20+
/// <param name="options">启动选项 / Startup options</param>
21+
/// <returns>包含启动结果的 <see cref="HotfixLaunchResult"/> / The <see cref="HotfixLaunchResult"/> containing the startup result</returns>
22+
public UniTask<HotfixLaunchResult> StartAsync(StartupOptions options)
23+
{
24+
return HotfixHelper.StartHotfixAsync(options);
25+
}
26+
}
27+
}

Assets/Scripts/Framework/Procedure/ApplicationHotfixLauncher.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Cysharp.Threading.Tasks;
2+
using GameFrameX.Startup.Runtime;
3+
4+
namespace GameFrameX.Startup.Application
5+
{
6+
/// <summary>
7+
/// 应用层启动 UI 处理实现,将 <see cref="LauncherUIHandler"/> 适配到 <see cref="IStartupUIHandler"/> 接口。
8+
/// </summary>
9+
/// <remarks>
10+
/// Application startup UI handler that adapts <see cref="LauncherUIHandler"/> to the <see cref="IStartupUIHandler"/> interface.
11+
/// </remarks>
12+
public sealed class ApplicationStartupUIHandler : IStartupUIHandler
13+
{
14+
/// <summary>
15+
/// 异步打开启动 UI。
16+
/// </summary>
17+
/// <remarks>
18+
/// Asynchronously open the startup UI.
19+
/// </remarks>
20+
/// <param name="uiResName">启动 UI 资源名称 / Startup UI asset name</param>
21+
/// <returns>异步任务 / The async task</returns>
22+
public UniTask StartAsync(string uiResName)
23+
{
24+
return LauncherUIHandler.StartAsync(uiResName);
25+
}
26+
27+
/// <summary>
28+
/// 设置提示文本。
29+
/// </summary>
30+
/// <remarks>
31+
/// Set the tip text.
32+
/// </remarks>
33+
/// <param name="text">要显示的提示文本 / The tip text to display</param>
34+
public void SetTipText(string text)
35+
{
36+
LauncherUIHandler.SetTipText(text);
37+
}
38+
39+
/// <summary>
40+
/// 设置下载进度。
41+
/// </summary>
42+
/// <remarks>
43+
/// Set the download progress.
44+
/// </remarks>
45+
/// <param name="progress">下载进度,取值范围 [0, 1] / Download progress in range [0, 1]</param>
46+
/// <param name="sizeInfo">已下载与总大小信息字符串 / Downloaded size and total size info string</param>
47+
public void SetProgress(float progress, string sizeInfo)
48+
{
49+
LauncherUIHandler.SetProgress(progress, sizeInfo);
50+
}
51+
52+
/// <summary>
53+
/// 标记下载流程完成。
54+
/// </summary>
55+
/// <remarks>
56+
/// Mark the download process as finished.
57+
/// </remarks>
58+
public void SetProgressUpdateFinish()
59+
{
60+
LauncherUIHandler.SetProgressUpdateFinish();
61+
}
62+
63+
/// <summary>
64+
/// 异步显示强制或可选更新提示。
65+
/// </summary>
66+
/// <remarks>
67+
/// Asynchronously show the force or optional update prompt.
68+
/// </remarks>
69+
/// <param name="upgradeInfo">启动器更新信息 / The launcher upgrade info</param>
70+
/// <returns>异步任务,返回用户是否继续 / The async task returning whether the user continues</returns>
71+
public UniTask<bool> ShowUpgradeAsync(StartupUpgradeInfo upgradeInfo)
72+
{
73+
return LauncherUIHandler.ShowUpgradeAsync(upgradeInfo);
74+
}
75+
76+
/// <summary>
77+
/// 关闭启动 UI 并释放资源。
78+
/// </summary>
79+
/// <remarks>
80+
/// Close the startup UI and release resources.
81+
/// </remarks>
82+
public void Dispose()
83+
{
84+
LauncherUIHandler.Dispose();
85+
}
86+
}
87+
}

Assets/Scripts/Framework/Procedure/ApplicationStartupUIHandler.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,83 @@
1-
using GameFrameX.Runtime;
1+
using System;
2+
using GameFrameX.Runtime;
3+
using Cysharp.Threading.Tasks;
4+
using GameFrameX.Startup.Runtime;
25
#if ENABLE_GAME_FRAME_X_HYBRID_CLR && !DISABLE_HYBRIDCLR
3-
using System;
46
using System.Reflection;
57
using System.Linq;
68
using HybridCLR;
79
#endif
810

9-
namespace Unity.Startup.Procedure
11+
namespace GameFrameX.Startup.Application
1012
{
13+
/// <summary>
14+
/// 热更启动辅助类,负责加载 AOT DLL 与热更程序集,并调用其入口方法。
15+
/// </summary>
16+
/// <remarks>
17+
/// Hotfix startup helper responsible for loading AOT DLLs and the hotfix assembly, then invoking its entry method.
18+
/// </remarks>
1119
public static class HotfixHelper
1220
{
13-
#if (ENABLE_GAME_FRAME_X_HYBRID_CLR && !DISABLE_HYBRIDCLR)
14-
const string HotfixName = "Unity.Hotfix";
15-
#endif
16-
public static
21+
/// <summary>
22+
/// 以默认选项启动热更程序集。
23+
/// </summary>
24+
/// <remarks>
25+
/// Start the hotfix assembly with default options.
26+
/// </remarks>
27+
public static async void StartHotfix()
28+
{
29+
await StartHotfixAsync(null);
30+
}
31+
32+
/// <summary>
33+
/// 异步加载并启动热更程序集。
34+
/// </summary>
35+
/// <remarks>
36+
/// Asynchronously load and start the hotfix assembly.
37+
/// </remarks>
38+
/// <param name="options">启动选项;为 null 时使用默认配置 / Startup options; default configuration is used when null</param>
39+
/// <returns>包含启动结果与错误信息的 <see cref="HotfixLaunchResult"/> / The <see cref="HotfixLaunchResult"/> containing startup result and error info</returns>
40+
public static async UniTask<HotfixLaunchResult> StartHotfixAsync(StartupOptions options)
41+
{
42+
try
43+
{
44+
await StartHotfixInternalAsync(options);
45+
return HotfixLaunchResult.Succeed();
46+
}
47+
catch (Exception e)
48+
{
49+
Log.Error(e);
50+
return HotfixLaunchResult.Fail(e.Message);
51+
}
52+
}
53+
54+
private static
1755
#if ENABLE_GAME_FRAME_X_HYBRID_CLR && !DISABLE_HYBRIDCLR
18-
async
56+
async UniTask
57+
#else
58+
UniTask
1959
#endif
20-
void StartHotfix()
60+
StartHotfixInternalAsync(StartupOptions options)
2161
{
62+
var assemblyName = options == null || string.IsNullOrEmpty(options.HotfixAssemblyName)
63+
? "Unity.Hotfix"
64+
: options.HotfixAssemblyName;
65+
var entryTypeName = options == null || string.IsNullOrEmpty(options.HotfixEntryTypeName)
66+
? "Hotfix.HotfixLauncher"
67+
: options.HotfixEntryTypeName;
68+
var entryMethodName = options == null || string.IsNullOrEmpty(options.HotfixEntryMethodName)
69+
? "Main"
70+
: options.HotfixEntryMethodName;
71+
2272
#if ENABLE_GAME_FRAME_X_HYBRID_CLR && !DISABLE_HYBRIDCLR
2373
if (ApplicationHelper.IsEditor)
2474
{
2575
var assemblies = Utility.Assembly.GetAssemblies();
2676
foreach (var assembly in assemblies)
2777
{
28-
if (assembly.GetName().Name.Equals(HotfixName, StringComparison.OrdinalIgnoreCase))
78+
if (assembly.GetName().Name.Equals(assemblyName, StringComparison.OrdinalIgnoreCase))
2979
{
30-
Run(assembly);
80+
Run(assembly, entryTypeName, entryMethodName);
3181
break;
3282
}
3383
}
@@ -46,37 +96,38 @@ void StartHotfix()
4696
}
4797

4898
Log.Info("结束加载AOT DLL");
49-
Log.Info("开始加载Unity.Hotfix.dll");
50-
var assetHotfixDllPath = Utility.Asset.Path.GetCodePath(HotfixName + Utility.Const.FileNameSuffix.DLL);
99+
Log.Info("开始加载" + assemblyName + ".dll");
100+
var assetHotfixDllPath = Utility.Asset.Path.GetCodePath(assemblyName + Utility.Const.FileNameSuffix.DLL);
51101
var assetHotfixDllOperationHandle = await GameApp.Asset.LoadAssetAsync<UnityEngine.Object>(assetHotfixDllPath);
52102
var assemblyDataHotfixDll = assetHotfixDllOperationHandle.GetAssetObject<UnityEngine.TextAsset>().bytes;
53103
Log.Info("开始加载程序集Hotfix");
54104
var hotfixAssembly = Assembly.Load(assemblyDataHotfixDll, null);
55-
Run(hotfixAssembly);
105+
Run(hotfixAssembly, entryTypeName, entryMethodName);
56106

57107
#else
58-
RunNative();
108+
RunNative(entryTypeName, entryMethodName);
109+
return UniTask.CompletedTask;
59110
#endif
60111
}
61112
#if ENABLE_GAME_FRAME_X_HYBRID_CLR && !DISABLE_HYBRIDCLR
62-
private static void Run(Assembly assembly)
113+
private static void Run(Assembly assembly, string entryTypeName, string entryMethodName)
63114
{
64115
Log.Info("加载程序集Hotfix 结束 Assembly " + assembly.FullName);
65-
var entryType = assembly.GetType("Hotfix.HotfixLauncher");
116+
var entryType = assembly.GetType(entryTypeName);
66117
Log.Info("加载程序集Hotfix 结束 EntryType " + entryType.FullName);
67-
var method = entryType.GetMethod("Main");
118+
var method = entryType.GetMethod(entryMethodName);
68119
Log.Info("加载程序集Hotfix 结束 EntryType=>method " + method?.Name);
69120
method?.Invoke(null, null);
70121
}
71122
#else
72-
private static void RunNative()
123+
private static void RunNative(string entryTypeName, string entryMethodName)
73124
{
74-
var entryType = Utility.Assembly.GetType("Hotfix.HotfixLauncher");
125+
var entryType = Utility.Assembly.GetType(entryTypeName);
75126
Log.Info("加载程序集Hotfix 结束 EntryType " + entryType.FullName);
76-
var method = entryType.GetMethod("Main");
127+
var method = entryType.GetMethod(entryMethodName);
77128
Log.Info("加载程序集Hotfix 结束 EntryType=>method " + method?.Name);
78129
method?.Invoke(null, null);
79130
}
80131
#endif
81132
}
82-
}
133+
}

Assets/Scripts/Framework/Procedure/HttpHelper.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

Assets/Scripts/Framework/Procedure/HttpHelper.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)