BundleHelper
Coding Style wiki
BundleHelper 是 AssetLoader 的编辑器(Editor)辅助工具,用于输出 App 配置文件(AppConfig)、补丁配置文件(PatchConfig)、资源包(Bundles)与 CDN 部署配置文件(CdnConfig),并提供群组/DLC 参数字符串的解析与转换,便于命令行(CI/CD)集成。
| 命名空间 | OxGFrame.AssetLoader.Editor |
| 类型 | public static class |
| 源码 | BundleHelper.cs |
using OxGFrame.AssetLoader.Editor;
注意 本类仅供 Unity Editor 环境使用。
方法总览
输出 (Exporter)
| 方法 | 说明 |
|---|---|
| ExportAppConfig | 输出 App 配置文件(默认 AppInfo.json)至指定路径(通常为 StreamingAssets)。 |
| ExportConfigsAndAppBundles | 输出配置文件(AppConfig / PatchConfig)与最新 App Bundles 至 CDN 输出路径。 |
| ExportAppBundles | 仅输出最新 App Bundles(不含配置文件)。 |
| ExportIndividualDlcBundles | 输出独立版本管控的 DLC Bundles。 |
| ExportBundleUrlConfig | 输出 CDN 部署配置文件(默认 CdnConfig.dat),支持加密。 |
解析与转换 (Parser & Converter)
| 方法 | 说明 |
|---|---|
| ParsingGroupInfosByArgs | 将字符串参数解析为 GroupInfo 列表。 |
| ConvertGroupInfosToArgs | 将 GroupInfo 列表转换回字符串参数。 |
| ParsingDlcInfosByArgs | 将字符串参数解析为 DlcInfo 列表。 |
| ConvertDlcInfosToArgs | 将 DlcInfo 列表转换回字符串参数。 |
提醒 上述输出作业亦可通过编辑器菜单 OxGFrame → AssetLoader → Export Bundle And Config Generator 打开窗口工具执行(对应 ExportAppConfigToStreamingAssets、ExportConfigsAndAppBundlesForCDN、ExportAppBundlesWithoutConfigsForCDN、ExportIndividualDLCBundlesForCDN 四种作业类型)。
ExportAppConfig
public static void ExportAppConfig(string productName, string appVersion, string outputPath, bool activeBuildTarget, BuildTarget buildTarget)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| productName | string | 产品名称(写入 AppConfig 的 PRODUCT_NAME)。 |
| appVersion | string | 主程序版本。空值时自动使用 Application.version。 |
| outputPath | string | 输出目录路径(通常为 Application.streamingAssetsPath)。 |
| activeBuildTarget | bool | 是否使用当前编辑器的目标平台作为 PLATFORM。 |
| buildTarget | BuildTarget | 当 activeBuildTarget 为 false 时采用的目标平台。 |
说明
生成 AppConfig(PLATFORM、PRODUCT_NAME、APP_VERSION)并以 JSON 格式写入配置文件至指定路径,文件名由 PatchSettings 决定(默认 AppInfo.json)。通常输出至内置的 StreamingAssets,供客户端启动时读取比对版本。
示例
using OxGFrame.AssetLoader.Editor;
using UnityEditor;
using UnityEngine;
BundleHelper.ExportAppConfig(
"MyProduct",
"1.0.0",
Application.streamingAssetsPath,
true, // 使用当前编辑器的目标平台
BuildTarget.NoTarget // activeBuildTarget 为 true 时此参数不采用
);
ExportConfigsAndAppBundles
public static void ExportConfigsAndAppBundles(string inputPath, string outputPath, string productName, SemanticRule semanticRule, string appVersion, string[] exportPackages, List<GroupInfo> groupInfos, string[] packageInfos, bool activeBuildTarget, BuildTarget buildTarget, bool isClearOutputPath = true)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| inputPath | string | 原始 Bundles 输入路径。空值时自动使用 YooAsset 默认构建输出根目录。 |
| outputPath | string | CDN 资源输出路径。 |
| productName | string | 产品名称。 |
| semanticRule | SemanticRule | 版本语义化规则(AppConfig.SemanticRule)。PATCH 启用时版本文件夹为 v<Major>.<Minor>.<Patch>,否则为 v<Major>.<Minor>。 |
| appVersion | string | 主程序版本。空值时自动使用 Application.version。 |
| exportPackages | string[] | 要输出 Bundles 的 Package 名称列表。 |
| groupInfos | List<GroupInfo> | 资源群组信息列表(写入 PatchConfig 的 GROUP_INFOS,供补丁流程的群组下载选择)。 |
| packageInfos | string[] | 要记录于 PatchConfig 的 Package 名称列表(为每个 Package 统计总大小与版本信息,写入 PACKAGES)。 |
| activeBuildTarget | bool | 是否使用当前编辑器的目标平台。 |
| buildTarget | BuildTarget | 当 activeBuildTarget 为 false 时采用的目标平台。 |
| isClearOutputPath | bool | 输出前是否先清空输出文件夹。 默认值: true |
说明
一次完成 CDN 部署所需的完整输出:
- 从输入路径的各 Package 中筛选输出时间最新的版本文件夹,复制至
<outputPath>/<productName>/<platform>/<v版本>/<packageName>。 - 写入 AppConfig(默认
AppInfo.json,并在版本文件夹内附AppInfo.bak备份)与 PatchConfig(默认PatchInfo.json,并附PatchInfo.bak备份)。
重要 isClearOutputPath 为 true 时会先删除整个输出文件夹,请确认输出路径下无其他重要数据。
示例
using OxGFrame.AssetLoader.Bundle;
using OxGFrame.AssetLoader.Editor;
using UnityEditor;
var semanticRule = new AppConfig.SemanticRule(); // 默认 MAJOR.MINOR(PATCH 关闭)
var groupInfos = BundleHelper.ParsingGroupInfosByArgs("g1,t1#g2,t1,t2");
BundleHelper.ExportConfigsAndAppBundles(
null, // 使用 YooAsset 默认构建输出路径
"D:/CDN_Output",
"MyProduct",
semanticRule,
"1.0.0",
new string[] { "DefaultPackage" },
groupInfos,
new string[] { "DefaultPackage" },
true,
BuildTarget.NoTarget
);
ExportAppBundles
public static void ExportAppBundles(string inputPath, string outputPath, string productName, SemanticRule semanticRule, string appVersion, string[] exportPackages, bool activeBuildTarget, BuildTarget buildTarget, bool isClearOutputPath = true)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| inputPath | string | 原始 Bundles 输入路径。空值时自动使用 YooAsset 默认构建输出根目录。 |
| outputPath | string | CDN 资源输出路径。 |
| productName | string | 产品名称。 |
| semanticRule | SemanticRule | 版本语义化规则(决定版本文件夹格式)。 |
| appVersion | string | 主程序版本。空值时自动使用 Application.version。 |
| exportPackages | string[] | 要输出 Bundles 的 Package 名称列表。 |
| activeBuildTarget | bool | 是否使用当前编辑器的目标平台。 |
| buildTarget | BuildTarget | 当 activeBuildTarget 为 false 时采用的目标平台。 |
| isClearOutputPath | bool | 输出前是否先清空输出文件夹。 默认值: true |
说明
仅输出最新的 App Bundles 至 CDN 输出路径,不写入配置文件(AppConfig / PatchConfig)。适用于仅更新资源、无需变动配置的情况。
重要 isClearOutputPath 为 true 时会先删除整个输出文件夹。
ExportIndividualDlcBundles
public static void ExportIndividualDlcBundles(string inputPath, string outputPath, string productName, List<DlcInfo> dlcInfos, bool activeBuildTarget, BuildTarget buildTarget, bool isClearOutputPath = true)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| inputPath | string | 原始 Bundles 输入路径。空值时自动使用 YooAsset 默认构建输出根目录。 |
| outputPath | string | CDN 资源输出路径。 |
| productName | string | 产品名称。 |
| dlcInfos | List<DlcInfo> | DLC 信息列表(packageName、dlcVersion、withoutPlatform)。dlcVersion 为空时,自动采用该 Package 最新的版本号;withoutPlatform 为 true 时,输出路径省略平台层级。 |
| activeBuildTarget | bool | 是否使用当前编辑器的目标平台。 |
| buildTarget | BuildTarget | 当 activeBuildTarget 为 false 时采用的目标平台。 |
| isClearOutputPath | bool | 输出前是否先清空输出文件夹。 默认值: true |
说明
输出独立版本管控的 DLC Bundles 至 <outputPath>/<productName>/<platform>/<dlcFolderName>/<packageName>/<dlcVersion>(withoutPlatform 时省略 <platform> 层级;dlcFolderName 由 PatchSettings 决定,默认 DLC)。
提醒 DLC 具有独立版本路径,客户端通过 BundleConfig.GetDlcHostServerUrl 组合对应的下载端点。
ExportBundleUrlConfig
public static void ExportBundleUrlConfig(string bundleIp, string bundleFallbackIp, string storeLink, string outputPath, bool cipher)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| bundleIp | string | 主要 CDN 服务器 IP 或域名。空值时使用默认值 http://127.0.0.1。 |
| bundleFallbackIp | string | 备用 CDN 服务器 IP 或域名。空值时使用默认值 http://127.0.0.1。 |
| storeLink | string | 商店链接(Google Play / App Store)。空值时使用默认值 http://。 |
| outputPath | string | 输出目录路径(输出文件名由 PatchSettings 决定,默认 CdnConfig.dat)。 |
| cipher | bool | 是否加密输出。 |
说明
将 CDN 地址与商店链接输出成部署配置文件至指定路径,通常输出至内置的 StreamingAssets,供客户端解析资源请求端点。明文输出内容如下:
# bundle_ip = First CDN Server IP or Domain (Plan A)
# bundle_fallback_ip = Second CDN Server IP or Domain (Plan B)
# store_link = GooglePlay Store Link (https://play.google.com/store/apps/details?id=YOUR_ID)
# store_link = Apple Store Link (https://apps.apple.com/app/idYOUR_ID)
bundle_ip http://127.0.0.1
bundle_fallback_ip http://127.0.0.1
store_link http://
注意 启用 cipher 时,仅保留键值行(去除 # 注释行),内容以 PatchSettings.settings.bundleUrlCfgCipher 密钥进行 XOR 加密,并在文件头写入 2 字节的 PatchSettings.CIPHER_HEADER 标记;客户端由 BundleConfig.GetValueFromUrlCfg 读取时自动检测并解密。
提醒 亦可通过编辑器菜单 OxGFrame → AssetLoader → Bundle Url Config Generator (CdnConfig.dat) 打开窗口工具生成。
示例
using OxGFrame.AssetLoader.Editor;
using UnityEngine;
BundleHelper.ExportBundleUrlConfig(
"https://cdn.example.com",
"https://backup-cdn.example.com",
"https://play.google.com/store/apps/details?id=com.example.game",
Application.streamingAssetsPath,
true
);
ParsingGroupInfosByArgs
public static List<GroupInfo> ParsingGroupInfosByArgs(string groupInfoArgs)