跳到主要内容
版本:v3

HotfixHelper

重要 注意 提醒

Coding Style wiki


HotfixHelperHotfixer 的编辑器(Editor)辅助工具,用于编译与收集 AOT / Hotfix DLL 至 HotfixCollector 目录,并输出热更新 DLL 配置文件(HotfixManifest.dat),供运行时 Hotfixers.CheckHotfix 的自动配置模式读取。

命名空间OxGFrame.Hotfixer.Editor
类型public static class
源码HotfixHelper.cs
using OxGFrame.Hotfixer.Editor;

注意 本类仅供 Unity Editor 环境使用。

方法总览

方法说明
CompileAndCopyToHotfixCollector编译 Hotfix DLL 并一键收集 AOT / Hotfix DLL 至 HotfixCollector
CopyAOTDllsAndHotfixDlls一键复制 AOT 与 Hotfix DLL 至 HotfixCollector 目录。
CopyAOTAssembliesToDestination复制 AOT DLL(IL2CPP 裁剪后)至目标目录。
CopyHotfixAssembliesToDestination复制 Hotfix DLL 至目标目录。
ExportHotfixDllConfig输出热更新 DLL 配置文件(HotfixManifest.dat)至 StreamingAssets
ToRelativeAssetPath将绝对路径转换为以 Assets/ 开头的相对路径。

CompileAndCopyToHotfixCollector

public static void CompileAndCopyToHotfixCollector()

说明

依当前目标平台(activeBuildTarget)调用 HybridCLR 的 CompileDllCommand.CompileDll 编译热更新 DLL,接着执行 CopyAOTDllsAndHotfixDlls 将 AOT 与 Hotfix DLL 收集至 HotfixCollector 目录。

提醒 对应编辑器菜单 HybridCLR → OxGFrame With HybridCLR → Compile And Copy To HotfixCollector。收集完毕后,再使用 YooAsset Collector 进行收集打包,请参考收集示例


CopyAOTDllsAndHotfixDlls

public static void CopyAOTDllsAndHotfixDlls()

说明

一键依序执行 CopyAOTAssembliesToDestinationCopyHotfixAssembliesToDestination(皆使用默认输出目录),将所有相关文件收集至 Assets/HotfixCollector 目录中。


CopyAOTAssembliesToDestination

public static void CopyAOTAssembliesToDestination(string dstDir = null)

参数

参数类型说明
dstDirstring自定义输出目录。
默认值null(输出至 Assets/HotfixCollector/AOTDlls

说明

依当前目标平台,将 IL2CPP 裁剪后的 AOT DLL(清单来自 HybridCLR 的 SettingsUtil.AOTAssemblyNames)复制至目标目录,输出文件名为 <程序集名称>.dll.bytes,以便后续以资源形式收集加载。

注意 目标目录在复制前会先被删除重建,请勿在其中存放其他文件。

重要 裁剪后的 AOT DLL 仅在 HybridCLR → Generate All(或构建 Player)之后才会生成。若 Console 提示文件不存在,请先执行 Generate All


CopyHotfixAssembliesToDestination

public static void CopyHotfixAssembliesToDestination(string dstDir = null)

参数

参数类型说明
dstDirstring自定义输出目录。
默认值null(输出至 Assets/HotfixCollector/HotfixDlls

说明

依当前目标平台,将 HybridCLR 编译输出的热更新 DLL(清单来自 SettingsUtil.HotUpdateAssemblyFilesExcludePreserved)复制至目标目录,并自动附加 .bytes 扩展名(输出为 <程序集名称>.dll.bytes)。

注意 目标目录在复制前会先被删除重建,请勿在其中存放其他文件。


ExportHotfixDllConfig

public static void ExportHotfixDllConfig(List<string> aotDlls, List<string> hotfixDlls, bool cipher)

参数

参数类型说明
aotDllsList<string>需补充元数据(Metadata)的 AOT 程序集清单(名称含 .dll 扩展名)。
hotfixDllsList<string>热更新程序集清单(名称含 .dll 扩展名)。
cipherbool是否加密。true 输出加密 BYTES 格式;false 输出明文 JSON 格式。

说明

将 AOT 与 Hotfix 程序集清单写入热更新 DLL 配置文件,输出至内置的 StreamingAssets(文件名依 HotfixSettings 设置,默认为 HotfixManifest.dat),供运行时 Hotfixers.CheckHotfix 自动配置模式读取。

明文 JSON 格式内容如下:

{
"aotDlls": [
"mscorlib.dll",
"UniTask.dll"
],
"hotfixDlls": [
"HotfixerDemo.Hotfix.Runtime.dll"
]
}

加密 BYTES 格式会在文件头写入加密标记,内容以 HotfixSettingscipher 密钥进行 XOR 加密;运行时读取时依文件头自动判别格式。

提醒
  • 也可通过编辑器菜单 OxGFrame → Hotfixer → Hotfix Config Generator (HotfixManifest.dat) 打开窗口工具生成(支持 Preset Plans 预设方案管理)。
  • 已输出的配置文件可在 Project 窗口选中后,通过菜单 Assets → OxGFrame → Hotfixer → Convert HotfixManifest.dat (BYTES [Cipher] <-> JSON [Plaintext]) 进行明文与加密格式互转(仅对位于 StreamingAssets 内且文件名相符的配置文件有效)。

示例

using OxGFrame.Hotfixer.Editor;
using System.Collections.Generic;

HotfixHelper.ExportHotfixDllConfig(
// 需补充元数据的 AOT 程序集
new List<string> { "mscorlib.dll", "UniTask.dll" },
// 热更新程序集
new List<string> { "HotfixerDemo.Hotfix.Runtime.dll" },
// 加密输出
true
);

ToRelativeAssetPath

public static string ToRelativeAssetPath(string s)

参数

参数类型说明
sstring完整文件路径(需包含 Assets/ 路径段)。

返回值

string — 以 Assets/ 开头的项目相对路径。

说明

将绝对路径转换为相对于项目的 Assets/ 路径(截取字符串中 Assets/ 之后的部分)。