Version: 2022.1
包含特定场景
编译清单

在 Unity Cloud Build 中使用可寻址资源

Addressable Assets are assets that have a unique address which you can use to load them from local or remote AssetBundles.

先决条件

您必须执行以下操作,然后才能在 Cloud Build 中构建可寻址资源:

  • 转换您的项目从而在本地使用可寻址资源,即:
  • Install the Addressables package
  • 将资源设置为可寻址
  • 将更新的项目提交到所选的版本控制系统 (VCS)

Unity 建议您先确保能够在本地使用可寻址资源,然后再使用 Cloud Build 构建这些资源。

配置构建目标

如果要从全新的 Cloud Build 项目开始,需要先创建新的构建目标。

  1. From the Cloud Build Dashboard, navigate to the build target Configurations page for your project.
  2. Go to the build target that you’d like to build Addressables for.
  3. On the build target’s advanced settings, edit the Addressables section.

Use the Addressables section to configure properties that determine how the Addressables build process behaves. Each property is described in more detail with a tooltip.

运行新的可寻址资源构建

要运行新的可寻址资源构建,请执行以下操作:

  1. Enable Build Addressables.
  2. Click the Save changes button.
  3. Build the Target.

启用 Cloud Content Delivery 服务

If you want to upload Addressables to the Cloud Content Delivery (CCD) service from Cloud Build:

  1. Go to the build target that you’d like to build Addressables for.
  2. On the build target’s advanced settings, edit the Addressables section.
  3. Enable Upload Addressables to the Cloud Content Delivery service to upload Addressables to CCD.
  4. Choose the required CCD bucket in the Content Delivery Bucket drop-down.
  5. Your Content Delivery API Key should already be populated in its field. If not, add it.
  6. Enable Automatically create a Cloud Content Delivery release from the bucket if you want to automatically create a CCD release from the selected bucket.
  7. Click the Save changes button.
  8. Build the Target.

See Addressable Asset system with Cloud Content Delivery for more information about using Addressables with CCD.

运行内容更新构建

内容更新构建使用新的可寻址内容来更新以前构建的播放器。

要更新现有播放器,更新构建需要一个内容状态文件。这会将更新构建的内容链接到现有播放器。进行新的可寻址资源构建时,会生成内容状态文件。

要使用新的可寻址资源来更新以前构建的播放器,请执行以下操作:

  1. On the build target’s advanced settings, edit the Asset bundles section.
  2. Enable Make a content-only build.
  3. Click the Save changes button.

启动构建

配置构建目标后,要启动新的可寻址资源构建,请执行以下操作:

  1. 导航到控制面板的 Build History 页面。
  2. 构建需要配置可寻址资源的目标。

成功完成新构建后,此构建的 More 菜单 (⋮) 可显示 Download Addressable Assets 选项。

将可寻址资源内容从 Cloud Build 复制到您的托管服务提供商

完成可寻址资源构建后,可以将可寻址资源内容从 Cloud Build 复制到托管服务提供商。可以手动或者使用构建后脚本来执行此操作。

手动复制可寻址资源内容

完成可寻址资源构建后,从 More 菜单 (⋮) 中选择 Download Addressables Assets。下载内容后,您可以像在本地进行构建一样,将内容上传到托管服务提供商。

使用构建后脚本来复制可寻址资源内容

Cloud Build 支持在构建之前或之后运行自定义 shell 脚本。您可以创建构建后脚本,从而在构建成功完成后自动上传您的可寻址资源内容。

要启用构建后脚本,请执行以下操作:

  1. Go to the Cloud Build Configurations page.
  2. On your build target’s advanced settings, in the Script hooks section,
  3. In the Post-Build Script field, enter the path to your script.

在编写脚本时,以下提示可能很有用:

  • 构建的可寻址资源内容位于 $WORKSPACE/.build/last/<BUILD_TARGET_ID>/extra_data/addrs/

  • You can set environment variables for secret keys in the Build Target Configurations page.


包含特定场景
编译清单