欢迎光临散文网 会员登陆 & 注册

Unity_Addressable_Remote content distribution(远程内容分发)

2023-04-06 10:38 作者:unity_某某师_高锦锦  | 我要投稿

Distributing content remotely can reduce initial app download size and install time. You can also update remotely distributed assets without republishing your app or game

译:远程分发内容可以减少初始应用程序下载大小和安装时间。您还可以更新远程分发的资产,而无需重新发布您的应用或游戏

When you assign a remote URL as the Load Path of a group, the Addressables system loads assets in the group from that URL. When you enable the Build Remote Catalog option, Addressables looks up the addresses of any remote assets in the remote catalog, allowing you to make changes to Addressable assets without forcing users to update and reinstall the entire game or application.

译:当您将远程 URL 指定为组的加载路径时,Addressables 系统会从该 URL 加载组中的资产。当您启用构建远程目录选项时,Addressables 会在远程目录中查找任何远程资产的地址,从而允许您对可寻址资产进行更改,而无需强制用户更新和重新安装整个游戏或应用程序

After enabling remote distribution, you can build your content in two ways:

译:启用远程分发后,您可以通过两种方式构建您的内容

  • A full content build using the New Build > Default Build Script: builds all content bundles and catalogs. Always perform a full build before rebuilding your player when preparing to publish or update your full application.译:使用New Build > Default Build Script 的完整内容构建:构建所有内容包和目录。在准备发布或更新完整应用程序时,请始终在重建播放器之前执行完整构建

  • A content update build using the Update a Previous Build script: builds all content bundles and catalogs, but sets up the remote catalog so that installed applications only need to download the changed bundles. Run the Check for Content Update Restrictions tool to identify changes and prepare your groups before building an update.译:使用Update a Previous Build脚本的内容更新构建:构建所有内容包和目录,但设置远程目录以便已安装的应用程序只需要下载更改的包。运行检查内容更新限制工具以识别更改并在构建更新之前准备您的组

After building a full build or an update, you must upload your remote catalog, catalog hash file, and remote bundles to your hosting service.

译:构建完整构建或更新后,您必须将远程目录、目录哈希文件和远程包上传到托管服务

See Using Profiles to aid development for tips on setting up Addressables Profiles to help you develop, test, and publish remote content.

译:有关设置可寻址配置文件以帮助您开发、测试和发布远程内容的提示,请参阅使用配置文件来帮助开发


Enabling remote distribution

To enable remote distribution of your content, you must enable the remote catalog and set up the groups containing the assets you want to host remotely.

译:要启用内容的远程分发,您必须启用远程目录并设置包含您要远程托管的资产的组

Enabling the remote catalog

Enable the remote catalog in your Addressable Asset Settings Inspector (menu: Window > Asset Management > Addressables > Settings).

译:在可寻址资产设置检查器中启用远程目录(菜单:Window > Asset Management > Addressables > Settings

  • Build Remote Catalog: enabled译:构建远程目录:已启用

  • Build & Load Paths: Remote译:构建和加载路径:远程

启用远程目录

The catalog and its accompanying hash file are built to the folder specified by the Build Path setting. You must upload these files so that they can be accessed at the URL specified by your Load Path setting. Unless you have a specific reason not to, use the Remote location so that the catalog is built to and loaded from the same paths as your remote bundles.

译:目录及其随附的哈希文件构建到构建路径设置指定的文件夹中。您必须上传这些文件,以便可以通过加载路径设置指定的 URL 访问它们。除非您有特殊原因不这样做,否则请使用远程位置,以便将目录构建到与远程包相同的路径并从中加载

Setting up a remote group

To set up a group so that the assets in it can be hosted remotely, set the Build & Load Paths using the Remote location:

译:要设置一个组以便可以远程托管其中的资产,请使用远程位置设置构建和加载路径

If you plan to publish content updates between publishing full rebuilds of your application, set the Update Restriction value according to how often you expect to update content in a group.

译:如果您计划在发布应用程序的完整重建之间发布内容更新,请根据您希望在组中更新内容的频率设置更新限制值

Choose Cannot Change Post Release for groups that produce larger bundles, especially if you do not anticipate changing most of the assets in the group. If you do change assets in a group with this setting, the Addressables tools move the changed assets to a new group for the update. Only the new bundles are downloaded by installed applications.

译:为生成较大捆绑包的组选择无法更改发布后版本,尤其是当您预计不会更改组中的大部分资产时。如果您使用此设置更改组中的资产,Addressables 工具会将更改的资产移动到新组以进行更新。已安装的应用程序只会下载新的捆绑包

Choose Can Change Post Release for groups containing assets that you expect to change frequently. If you change assets in a group with this setting, the bundles containing those assets are rebuilt as a whole and will be redownloaded by installed applications. To reduce the amount of data that needs to be downloaded after an update, try to keep the bundles produced by groups with this setting as small as possible.

译:为包含您希望经常更改的资产的组选择可以更改发布后。如果您使用此设置更改组中的资产,则包含这些资产的包将作为一个整体重建,并将由已安装的应用程序重新下载。要减少更新后需要下载的数据量,请尝试使使用此设置的组生成的捆绑包尽可能小

See Content update builds for more information about updating remote content.

译:有关更新远程内容的更多信息,请参阅内容更新构建

The Advanced Options section contains some options that affect remote hosting and downloads (but aren't necessary to enable remote hosting). See Advanced Options for more information.

译:高级选项部分包含一些影响远程托管和下载的选项(但不是启用远程托管所必需的)。有关详细信息,请参阅高级选项

Using Profiles to aid development

A Profile defines variables that you can use to set the build and load paths for both your local and remote content.

译:配置文件定义可用于设置本地和远程内容的构建和加载路径的变量

When you distribute content remotely, you typically need to set different URLS (load paths) for your remote content depending on why you are making a build. Some examples of such situations include:

译:远程分发内容时,通常需要根据构建的原因为远程内容设置不同的 URLS(加载路径)。这种情况的一些例子包括

Builds for testing general game play and function

译:用于测试一般游戏玩法和功能的构建

Early in development or when you need to test without access to a host, you might find it convenient to treat all your content as local content. For this situation set the Local and Remote profile variables using the Built-In location.

译:在开发初期或需要在无法访问主机的情况下进行测试时,您可能会发现将所有内容视为本地内容很方便。对于这种情况,使用内置位置设置本地远程配置文件变量

All content treated as local_所有内容均视为本地内容

Builds for local hosting

Later, when you set up a host on your local network (or localhost), you will need to change the Load Path for your remote groups to reflect the URL of the host. For example if using Editor Hosting, set the Remote profile variable using the Editor Hosting location.

译:稍后,当您在本地网络(或本地主机)上设置主机时,您需要更改远程组的加载路径以反映主机的 URL。例如,如果使用编辑器托管,请使用编辑器托管位置设置远程配置文件变量

 Remote content served from Editor Hosting_从 Editor Hosting 提供的远程内容

Builds for CDN

As you get closer to production, you might use a staging server and then, your production Content Delivery Network (CDN). For example if using Cloud Content Delivery, set the Remote profile variable using the Cloud Content Delivery location.

译:当您接近生产时,您可能会使用暂存服务器,然后使用您的生产内容交付网络 (CDN)。例如,如果使用Cloud Content Delivery,请使用Cloud Content Delivery位置设置远程配置文件变量

Remote content hosted on the Unity Cloud Content Delivery service

Other

Even after release, you might want to use different host URLs for beta testing or other purposes.

译:即使在发布之后,您也可能希望使用不同的主机 URL 进行 Beta 测试或其他目的。

Rather than hand configuring the build and load paths every time you build, you can create a different Profile and set the variables appropriately. Then, you can easily switch between Profiles before making a content build without worrying about misconfiguring the paths.

译:您不必在每次构建时手动配置构建和加载路径,您可以创建一个不同的配置文件并适当地设置变量。然后,您可以在构建内容之前轻松地在配置文件之间切换,而不必担心路径配置错误

If you use a script to launch your content builds, then you can use the Addressables API to choose a specific Profile for a build. See Starting an Addressables build from a script.

译:如果您使用脚本来启动您的内容构建,那么您可以使用 Addressables API 为构建选择特定的配置文件。请参阅从脚本启动 Addressables 构建。

If you have complex URLs, you can reference static fields or properties in your Profile variables that are evaluated at build- or runtime. For example, rather than entering your CCD ProjectID as a string, you could create an Editor class that provides the information as a static property and reference it as, [CCDInfo.ProjectID]. See Profile variable syntax for more information. (InternalIdTransformFunc functions provide an additional method of handling complex URL requirements.)

译:如果您有复杂的 URL,您可以在您的 Profile 变量中引用在构建或运行时评估的静态字段或属性。例如,与其以字符串形式输入 CCD ProjectID,不如创建一个 Editor 类,以静态属性形式提供信息并将其引用为 [CCDInfo.ProjectID]。有关详细信息,请参阅配置文件变量语法。(InternalIdTransformFunc函数提供了一种处理复杂 URL 要求的附加方法。)

NOTE

If your remote URL requires cannot be expressed as a static string see Custom URL evaluation for information about how you can rewrite the URL for assets, including AssetBundles, at runtime.

译:如果您的远程 URL 要求不能表示为静态字符串,请参阅自定义 URL 评估,了解有关如何在运行时重写资产(包括 AssetBundle)的 URL 的信息

AssetBundle caching

By default, AssetBundles produced for an Addressables build are cached on the client device after they are downloaded. Cached bundles are only downloaded again if they are updated or if they are deleted from the cache.

译:默认情况下,为 Addressables 构建生成的 AssetBundle 在下载后缓存在客户端设备上。缓存的捆绑包只有在更新或从缓存中删除时才会再次下载

An updated catalog can exclude bundle entries present in an older version of the catalog. When these entries are cached, their data is no longer needed on the device.

译:更新的目录可以排除旧版本目录中存在的包条目。当这些条目被缓存时,设备上不再需要它们的数据

When you have unneeded cache data on the device, you can choose one of three options:

译:当设备上有不需要的缓存数据时,您可以选择以下三个选项之一

  • To delete the entire bundle cache, use Caching.ClearCache.译:要删除整个包缓存,请使用Caching.ClearCache

  • To remove cache entries that are no longer referenced at any time, use Addressables.CleanBundleCache. You usually call this function after initializing Addressables (see Customizing Addressables initialization) or after loading additional catalogs (see Managing catalogs at runtime).译:要随时删除不再引用的缓存条目,请使用Addressables.CleanBundleCache。您通常在初始化 Addressables(请参阅自定义 Addressables 初始化)或加载其他目录(请参阅在运行时管理目录)之后调用此函数

  • To automatically call Addressables.CleanBundleCache after updating catalogs, use the parameter autoCleanBundleCache in Addressables.UpdateCatalogs. See Checking for content updates at runtime for an example script.译:

  • 要在更新目录后自动调用Addressables.CleanBundleCache ,请使用Addressables.UpdateCatalogsautoCleanBundleCache中的参数。有关示例脚本,请参阅在运行时检查内容更新。

If you disable caching for a group, the remote bundles produced for the group are stored in memory when they are downloaded until you unload them or the application exits. The next time the application loads the bundle, Addressables downloads it again.

译:如果您禁用组的缓存,则为该组生成的远程包在下载时将存储在内存中,直到您卸载它们或应用程序退出。下次应用程序加载包时,Addressables 会再次下载它

You can control whether the bundles produced by a group are cached or not with the Use Asset Bundle Cache setting under Advanced Options in the Group Inspector.

译:您可以使用组检查器中高级选项下的使用资产包缓存设置来控制组生成的包是否被缓存

See AssetBundle compression for additional information about AssetBundle caching. The Addressables system sets the cache-related parameters of the UnityWebRequests it uses to download Addressable bundles based on the group settings.

译:有关 AssetBundle 缓存的更多信息,请参阅AssetBundle 压缩。Addressables 系统设置UnityWebRequests的缓存相关参数,它用于根据组设置下载 Addressable bundle

Note that there are some limitations for WebGL AssetBundles. For more information, see Building and running a WebGL project.

译:请注意,WebGL AssetBundle 有一些限制。有关详细信息,请参阅构建和运行 WebGL 项目

Pre-downloading remote content

In situations where you want to predownload content so that it is cached on disk and faster to access when the application needs it, you can use the Addressables.DownloadDependenciesAsync method. This method downloads an Addressable entity and any dependencies as a background task.

译:在您想要预下载内容以便将其缓存在磁盘上并在应用程序需要时更快地访问的情况下,您可以使用 Addressables.DownloadDependenciesAsync方法。此方法下载 Addressable 实体和任何依赖项作为后台任务。

Calling the Addressables.DownloadDependenciesAsync method loads the dependencies for the address or label that you pass in. Typically, this is the AssetBundle.

译:调用Addressables.DownloadDependenciesAsync方法加载您传入的地址或标签的依赖项。通常,这是 AssetBundle。

The AsyncOperationHandle struct returned by this call includes a PercentComplete attribute that you can use to monitor and display download progress. You can also have the app wait until the content has loaded.

译:此调用返回的AsyncOperationHandle结构包括可用于监视和显示下载进度的 PercentComplete 属性。您还可以让应用程序等待内容加载完毕

Regarding PercentComplete

PercentComplete takes into account several aspects of the underlying operations being handled by a single AsyncOperationHandle. There may be instances where the progression isn't linear, or some semblance of linear. This can be due to quick operations being weighted the same as operations that will take longer.

译:PercentComplete 考虑了由单个 AsyncOperationHandle 处理的基础操作的几个方面。在某些情况下,进展可能不是线性的,或者是线性的。这可能是由于快速操作与需要更长时间的操作的权重相同

For example, given an asset you wish to load from a remote location that takes a non-trivial amount of time to download and is reliant on a local bundle as a dependency you'll see your PercentComplete jump to 50% before continuing. This is because the local bundle is able to be loaded much quicker than the remote bundle. However, all the system is aware of is the need for two operations to be complete.

译:例如,给定您希望从远程位置加载的资产,该资产需要花费大量时间来下载并且依赖于本地包作为依赖项,您会看到 PercentComplete 跳到 50%,然后再继续。这是因为本地包的加载速度比远程包快得多。但是,系统只知道需要完成两个操

If you wish to ask the user for consent prior to download, use Addressables.GetDownloadSize to return how much space is needed to download the content from a given address or label. Note that this takes into account any previously downloaded bundles that are still in Unity's AssetBundle cache.

译:如果您希望在下载之前征求用户的同意,请使用Addressables.GetDownloadSize返回从给定地址或标签下载内容需要多少空间。请注意,这会考虑仍在 Unity 的 AssetBundle 缓存中的所有先前下载的包。

While it can be advantageous to download assets for your app in advance, there are instances where you might choose not to do so. For example:

译:虽然提前为您的应用下载资产可能是有利的,但在某些情况下您可能选择不这样做。例如:

  • If your app has a large amount of online content, and you generally expect users to only ever interact with a portion of it.译:如果您的应用包含大量在线内容,并且您通常希望用户只与其中的一部分进行交互

  • You have an app that must be connected online to function. If all your app's content is in small bundles, you might choose to download content as needed.译:您有一个必须在线连接才能运行的应用程序。如果您应用程序的所有内容都打包成小包,您可以选择根据需要下载内容

Rather than using the percent complete value to wait until the content is loaded, you can use the preload functionality to show that the download has started, then continue on. This implementation would require a loading or waiting screen to handle instances where the asset has not finished loading by the time it's needed.

译:您可以使用预加载功能来显示下载已开始,然后继续,而不是使用完成百分比值等到内容加载完毕。此实现需要一个加载或等待屏幕来处理资产在需要时尚未完成加载的情况

Custom URL evaluation

There are several scenarios where you might need to customize the path or URL of an Asset (an AssetBundle generally) at runtime. The most common example is creating signed URLs. Another is dynamic host determination.

译:在多种情况下,您可能需要在运行时自定义资产(通常是 AssetBundle)的路径或 URL。最常见的示例是创建签名 URL。另一个是动态主机确定


Unity_Addressable_Remote content distribution(远程内容分发)的评论 (共 条)

分享到微博请遵守国家法律