文档

支持

使用 Build Automation 构建 Addressables

Follow this workflow to build Addressable Assets.
阅读时间4 分钟最后更新于 19 天前

可寻址资源是具有唯一地址的资源,您可以利用该地址从本地或远程 AssetBundles 加载这些资源。

先决条件

在 Build Automation 中构建可寻址资源之前,必须:
  • 在本地将项目转换为使用 Addressables:
    • 安装 Addressables 包
    • 将 Assets(资源)设置为 Addressable(可寻址)。
  • 将更新后的项目提交到所选的版本控制系统 (VCS)。

构建配置

要从新的 Build Automation 项目开始,需要首先创建新的构建配置
  1. 登录 Unity Dashboard
  2. 选择 DevOps > Build Automation > Configurations(配置)
  3. 选择要为其构建 Addressables 的构建配置。
  4. 选择 Edit(编辑)
  5. Advanced settings(高级设置) 选项卡中,选择 Yes, build Addressables(是,构建 Addressables)
使用 Addressables 部分来配置相关属性,这些属性将决定可寻址资源构建过程的行为方式。工具提示更详细地描述了每个属性。

运行新的 Addressables 构建

要运行新的 Addressables 构建,请执行以下操作:
  1. 转到 DevOps > Build Automation > Configurations(配置)
  2. 选择已配置 Addressables 设置的构建配置。
  3. 选择 Build(构建)
有关更多信息,请参阅手动运行构建

启用 Cloud Content Delivery 服务

要从 Build Automation 将 Addressables 上传到 Cloud Content Delivery (CCD) 服务,请执行以下操作:
  1. 从构建目标的高级设置中,导航到 Addressables 部分。
  2. 选择 Upload Addressables to the Cloud Content Delivery service(将 Addressables 上传到 Cloud Content Delivery 服务)
  3. Content Delivery Bucket(Content Delivery 存储桶) 下拉选单中,选择所需的 CCD 存储桶。
  4. 如果 Content Delivery API Key(Content Delivery API 密钥) 字段中未填充 API 密钥,请添加该 API 密钥。
  5. 要从所选存储桶自动创建 CCD 版本,请选择 Automatically create a Cloud Content Delivery release from the bucket(自动从存储桶创建 Cloud Content Delivery 版本)
  6. 选择 Save and build(保存并构建)
有关将 Addressables 与 CCD 结合使用的更多信息,请参阅 CCD + Addressables 演练

运行内容更新构建

内容更新构建使用新的可寻址资源内容更新先前构建的播放器。 要更新现有的播放器,更新构建需要一个内容状态文件。这会将更新构建中的内容与现有播放器关联起来。执行新的 Addressables 构建时,会生成内容状态文件。 要使用新的可寻址资源更新先前构建的播放器,请执行以下操作:
  1. 选择 Edit Addressables Asset Options(编辑 Addressables 资源选项)
  2. 选择 Yes, build Addressables(是,构建 Addressables)Make a content-update build(进行内容更新构建)
  3. 选择 Make a content-only build(进行仅内容构建),除非要生成另一个播放器。
  4. 设置内容状态文件位置方法,以定义 Build Automation 如何获取内容状态文件。
    Build Automation 可通过下列方式获取此文件。
    • 要从源代码控制获取该文件,请指定路径。
    • 要从先前已成功构建 Addressables 的现有构建目标获取该文件,请指定目标。
Build Automation 可以自动使用所选构建目标生成的最新内容状态文件。

开始构建

配置构建目标后,要启动新的 Addressables 构建,请执行以下操作:
  1. 导航到 Build AutomationBuild History(构建历史记录)
  2. 构建已为其配置 Addressables 的目标。有关如何运行构建的更多信息,请参阅手动运行构建
当新的构建成功完成后,构建的“更多”菜单 (⋮) 将显示 Download Addressable Assets(下载可寻址资源) 选项。

将 Addressables 内容从 Build Automation 复制到托管提供商

完成 Addressables 构建后,可以将 Addressables 内容从 Build Automation 复制到托管提供商。您可以手动复制内容,也可以使用构建后脚本。

手动复制 Addressables 内容

完成 Addressables 构建后,从“更多”菜单 (⋮) 中选择 Download Addressables Assets(下载 Addressables 资源)。下载内容时,可以在本地构建时将其上传到托管提供商。

使用构建后脚本复制 Addressables 内容

Build Automation 支持在构建之前或之后运行自定义 shell 脚本。您可以创建构建后脚本,以便在构建成功完成时自动上传 Addressables 内容。 要启用构建后脚本,请执行以下操作:
  1. 导航到 Build Automation Configurations(配置) 页面。
  2. 在构建目标上,选择 Edit Advanced Options(编辑高级选项)
  3. Post-Build Script Path(构建后脚本路径) 字段中,输入脚本的路径。
编写脚本时,请考虑以下信息:
  • 构建的可寻址资源内容位于
    $OUTPUT_DIRECTORY/extra_data/addrs
  • 您可以在构建目标 Configurations(配置) 页面中为密钥设置环境变量。