跳至主要内容
版本: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/ 之後的部分)。