Skip to main content
Version: v3

BundleHelper

Important Attention Reminder

Coding Style wiki


BundleHelper is the editor helper of AssetLoader. It exports the app config (AppConfig), patch config (PatchConfig), asset bundles, and the CDN deployment config (CdnConfig), and provides parsing/conversion of group and DLC argument strings for command-line (CI/CD) integration.

NamespaceOxGFrame.AssetLoader.Editor
Typepublic static class
SourceBundleHelper.cs
using OxGFrame.AssetLoader.Editor;

Attention This class is intended for the Unity Editor environment only.

Method Overview

Exporter

MethodDescription
ExportAppConfigExports the app config (default AppInfo.json) to a given path (usually StreamingAssets).
ExportConfigsAndAppBundlesExports the configs (AppConfig / PatchConfig) and the newest app bundles to the CDN output path.
ExportAppBundlesExports only the newest app bundles (without configs).
ExportIndividualDlcBundlesExports independently versioned DLC bundles.
ExportBundleUrlConfigExports the CDN deployment config (default CdnConfig.dat), with optional encryption.

Parser & Converter

MethodDescription
ParsingGroupInfosByArgsParses an argument string into a GroupInfo list.
ConvertGroupInfosToArgsConverts a GroupInfo list back into an argument string.
ParsingDlcInfosByArgsParses an argument string into a DlcInfo list.
ConvertDlcInfosToArgsConverts a DlcInfo list back into an argument string.

Reminder These export operations can also be performed via the editor menu OxGFrame → AssetLoader → Export Bundle And Config Generator, a window tool covering the four operation types: ExportAppConfigToStreamingAssets, ExportConfigsAndAppBundlesForCDN, ExportAppBundlesWithoutConfigsForCDN, and ExportIndividualDLCBundlesForCDN.


ExportAppConfig

public static void ExportAppConfig(string productName, string appVersion, string outputPath, bool activeBuildTarget, BuildTarget buildTarget)

Parameters

ParameterTypeDescription
productNamestringProduct name (written into the PRODUCT_NAME of the AppConfig).
appVersionstringApp version. If null or empty, Application.version is used automatically.
outputPathstringOutput directory path (usually Application.streamingAssetsPath).
activeBuildTargetboolWhether to use the editor's current build target as the PLATFORM.
buildTargetBuildTargetThe build target used when activeBuildTarget is false.

Description

Generates the AppConfig (PLATFORM, PRODUCT_NAME, APP_VERSION) and writes it as JSON to the given path. The file name is determined by PatchSettings (AppInfo.json by default). Usually exported into the built-in StreamingAssets so the client can read it at startup for version comparison.

Example

using OxGFrame.AssetLoader.Editor;
using UnityEditor;
using UnityEngine;

BundleHelper.ExportAppConfig(
"MyProduct",
"1.0.0",
Application.streamingAssetsPath,
true, // Use the editor's current build target
BuildTarget.NoTarget // Not used when activeBuildTarget is 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)

Parameters

ParameterTypeDescription
inputPathstringSource bundle input path. If null or empty, YooAsset's default build output root is used.
outputPathstringCDN output path.
productNamestringProduct name.
semanticRuleSemanticRuleSemantic versioning rule (AppConfig.SemanticRule). With PATCH enabled, the version folder is v<Major>.<Minor>.<Patch>; otherwise v<Major>.<Minor>.
appVersionstringApp version. If null or empty, Application.version is used automatically.
exportPackagesstring[]Names of the packages whose bundles are exported.
groupInfosList<GroupInfo>Asset group info list (written into the GROUP_INFOS of the PatchConfig, used for group download selection in the patch flow).
packageInfosstring[]Names of the packages to record in the PatchConfig (total size and version info are computed per package and written into PACKAGES).
activeBuildTargetboolWhether to use the editor's current build target.
buildTargetBuildTargetThe build target used when activeBuildTarget is false.
isClearOutputPathboolWhether to clear the output folder before exporting.
Default: true

Description

Performs the complete export needed for CDN deployment in one call:

  • Picks the version folder with the newest build time from each package under the input path and copies it to <outputPath>/<productName>/<platform>/<vVersion>/<packageName>.
  • Writes the AppConfig (default AppInfo.json, plus an AppInfo.bak backup inside the version folder) and the PatchConfig (default PatchInfo.json, plus a PatchInfo.bak backup).

Important With isClearOutputPath set to true, the entire output folder is deleted first — make sure it contains no other important data.

Example

using OxGFrame.AssetLoader.Bundle;
using OxGFrame.AssetLoader.Editor;
using UnityEditor;

var semanticRule = new AppConfig.SemanticRule(); // Default MAJOR.MINOR (PATCH disabled)
var groupInfos = BundleHelper.ParsingGroupInfosByArgs("g1,t1#g2,t1,t2");

BundleHelper.ExportConfigsAndAppBundles(
null, // Use YooAsset's default build output path
"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)

Parameters

ParameterTypeDescription
inputPathstringSource bundle input path. If null or empty, YooAsset's default build output root is used.
outputPathstringCDN output path.
productNamestringProduct name.
semanticRuleSemanticRuleSemantic versioning rule (determines the version folder format).
appVersionstringApp version. If null or empty, Application.version is used automatically.
exportPackagesstring[]Names of the packages whose bundles are exported.
activeBuildTargetboolWhether to use the editor's current build target.
buildTargetBuildTargetThe build target used when activeBuildTarget is false.
isClearOutputPathboolWhether to clear the output folder before exporting.
Default: true

Description

Exports only the newest app bundles to the CDN output path, without writing the configs (AppConfig / PatchConfig). Useful when only assets change and the configs stay the same.

Important With isClearOutputPath set to true, the entire output folder is deleted first.


ExportIndividualDlcBundles

public static void ExportIndividualDlcBundles(string inputPath, string outputPath, string productName, List<DlcInfo> dlcInfos, bool activeBuildTarget, BuildTarget buildTarget, bool isClearOutputPath = true)

Parameters

ParameterTypeDescription
inputPathstringSource bundle input path. If null or empty, YooAsset's default build output root is used.
outputPathstringCDN output path.
productNamestringProduct name.
dlcInfosList<DlcInfo>DLC info list (packageName, dlcVersion, withoutPlatform). If dlcVersion is null or empty, the newest version number of the package is used automatically; with withoutPlatform set to true, the platform level is omitted from the output path.
activeBuildTargetboolWhether to use the editor's current build target.
buildTargetBuildTargetThe build target used when activeBuildTarget is false.
isClearOutputPathboolWhether to clear the output folder before exporting.
Default: true

Description

Exports independently versioned DLC bundles to <outputPath>/<productName>/<platform>/<dlcFolderName>/<packageName>/<dlcVersion> (the <platform> level is omitted with withoutPlatform; dlcFolderName is determined by PatchSettings, DLC by default).

Reminder DLC packages have their own version paths; the client composes the corresponding download endpoint via BundleConfig.GetDlcHostServerUrl.


ExportBundleUrlConfig

public static void ExportBundleUrlConfig(string bundleIp, string bundleFallbackIp, string storeLink, string outputPath, bool cipher)

Parameters

ParameterTypeDescription
bundleIpstringPrimary CDN server IP or domain. If null or empty, the default http://127.0.0.1 is used.
bundleFallbackIpstringFallback CDN server IP or domain. If null or empty, the default http://127.0.0.1 is used.
storeLinkstringStore link (Google Play / App Store). If null or empty, the default http:// is used.
outputPathstringOutput directory path (the file name is determined by PatchSettings, CdnConfig.dat by default).
cipherboolWhether to encrypt the output.

Description

Exports the CDN addresses and store link as the deployment config to the given path, usually into the built-in StreamingAssets, so the client can resolve the bundle request endpoints. The plaintext output looks like this:

# 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://

Attention With cipher enabled, only the key-value lines are kept (the # comment lines are removed), the content is XOR-encrypted with the PatchSettings.settings.bundleUrlCfgCipher key, and the 2-byte PatchSettings.CIPHER_HEADER mark is written at the head of the file. The client detects and decrypts it automatically when reading via BundleConfig.GetValueFromUrlCfg.

Reminder The config can also be generated via the editor menu OxGFrame → AssetLoader → Bundle Url Config Generator (CdnConfig.dat).

Example

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)

Parameters

ParameterTypeDescription
groupInfoArgsstringGroup argument string. Format: <groupName>,<tag1>,<tag2>..., with multiple groups separated by # (e.g., g1,t1#g2,t1,t2).

Returns

List<GroupInfo> — the parsed group info list; an empty list if the input is null/empty or parsing fails.

Description

Parses a string argument into a list of GroupInfo objects (in each group, the first element is groupName and the rest are tags), which makes it easy to pass group settings as strings on the command line (CI/CD).

Example

var groupInfos = BundleHelper.ParsingGroupInfosByArgs("g1,t1#g2,t1,t2");
// groupInfos[0].groupName = "g1", tags = ["t1"]
// groupInfos[1].groupName = "g2", tags = ["t1", "t2"]

ConvertGroupInfosToArgs

public static string ConvertGroupInfosToArgs(List<GroupInfo> groupInfos)

Parameters

ParameterTypeDescription
groupInfosList<GroupInfo>Group info list.

Returns

string — the converted argument string (e.g., g1,t1#g2,t1,t2); an empty string for an empty list.

Description

Converts a list of GroupInfo objects back into the string format for command-line passing (the inverse of ParsingGroupInfosByArgs).


ParsingDlcInfosByArgs

public static List<DlcInfo> ParsingDlcInfosByArgs(string dlcInfoArgs)

Parameters

ParameterTypeDescription
dlcInfoArgsstringDLC argument string. Format: <packageName>,<version>, with multiple entries separated by # (e.g., dlc1,1.0.0#dlc2,1.1.0).

Returns

List<DlcInfo> — the parsed DLC info list; an empty list if the input is null/empty or parsing fails.

Description

Parses a string argument into a list of DlcInfo objects (in each entry, the elements are packageName and dlcVersion in order), which makes it easy to pass DLC settings as strings on the command line (CI/CD).

Example

var dlcInfos = BundleHelper.ParsingDlcInfosByArgs("dlc1,1.0.0#dlc2,1.1.0");
// dlcInfos[0].packageName = "dlc1", dlcVersion = "1.0.0"
// dlcInfos[1].packageName = "dlc2", dlcVersion = "1.1.0"

ConvertDlcInfosToArgs

public static string ConvertDlcInfosToArgs(List<DlcInfo> dlcInfos)

Parameters

ParameterTypeDescription
dlcInfosList<DlcInfo>DLC info list.

Returns

string — the converted argument string (e.g., dlc1,1.0.0#dlc2,1.1.0); an empty string for an empty list.

Description

Converts a list of DlcInfo objects back into the string format for command-line passing (the inverse of ParsingDlcInfosByArgs).