Unity_Addressable_Preloading dependencies(预加载依赖项)
Preloading dependencies
When you distribute content remotely, you can sometimes improve perceived performance by downloading dependencies in advance of when your application needs them. For example, you can download essential content on start up the first time a player launches your game to make sure that they don't have to wait for content in the middle of game play.
译:在远程分发内容时,有时可以通过预先下载应用程序需要的依赖项来改善感知性能。例如,您可以在玩家第一次启动游戏时,在启动时下载必要内容,以确保他们不必在游戏过程中等待内容。
Downloading dependencies
Use the Addressables.DownloadDependenciesAsync method to make sure that all the dependencies needed to load an Addressable key are available either in local content installed with the app or the download cache.
译:使用Addressables.DownloadDependenciesAsync方法,确保加载Addressable键所需的所有依赖项都可在已安装应用程序的本地内容或下载缓存中使用。
TIP
if you have a set of assets that you want to pre-download, you can assign the same label, such as "preload", to the assets and use that label as the key when calling Addressables.DownloadDependenciesAsync. Addressables downloads all the AssetBundles containing an asset with that label if not already available (along with any bundles containing the assets' dependencies).
译:如果您有一组要预先下载的资产,则可以将相同的标签(例如“preload”)分配给这些资产,并在调用Addressables.DownloadDependenciesAsync时将该标签用作键。如果不可用,则Addressables会下载包含具有该标签的资产的所有AssetBundle(以及任何包含资产依赖项的束)。
Progress
An AsyncOperationHandle instance provides two ways to get progress:
译:AsyncOperationHandle实例提供两种获取进度的方法:
AsyncOperationHandle.PercentComplete: reports the percentage of sub-operations that have finished. For example, if an operation uses six sub-operations to perform its task, the
PercentComplete
indicates the entire operation is 50% complete when three of those operations have finished (it doesn't matter how much data each operation loads).译:AsyncOperationHandle.PercentComplete :报告已完成子操作的百分比。例如,如果一个操作使用六个子操作执行其任务,则PercentComplete指示当其中三个操作完成时,整个操作已经完成了50%(不管每个操作加载多少数据)。AsyncOperationHandle.GetDownloadStatus: returns a DownloadStatus struct that reports the percentage in terms of total download size. For example, if an operation has six sub-operations, but the first operation represented 50% of the total download size, then
GetDownloadStatus
indicates the operation is 50% complete when the first operation finishes.译:AsyncOperationHandle.GetDownloadStatus :返回一个DownloadStatus结构,该结构按照总下载大小报告百分比。例如,如果操作有六个子操作,但第一个操作代表总下载大小的50%,则GetDownloadStatus在第一个操作完成时指示操作已经完成50%。
The following example illustrates how you could use GetDownloadStatus to check the status and dispatch progress events during the download:
译:以下示例说明了如何使用GetDownloadStatus检查状态并在下载期间调度进度事件:
To discover how much data you need to download in order to load one or more assets, you can call Addressables.GetDownloadSizeAsync:
译:要发现需要下载多少数据才能加载一个或多个资产,您可以调用Addressables.GetDownloadSizeAsync:
The Result of the completed operation is the number of bytes that must be downloaded. If Addressables has already cached all the required AssetBundles, then Result is zero.
译:完成操作的结果是必须下载的字节数。如果Addressables已经缓存了所有必需的AssetBundle,则Result为零。
Always release the download operation handle after you have read the Result object. If you don't need to access the results of the download operation, you can automatically release the handle by setting the autoReleaseHandle
parameter to true, as shown in the following example:
译:在阅读结果对象后,始终释放下载操作句柄。如果您不需要访问下载操作的结果,则可以通过将autoReleaseHandle参数设置为true来自动释放句柄,如下例所示:
Clearing the dependency cache
If you want to clear any AssetBundles cached by Addressables, call Addressables.ClearDependencyCacheAsync. This function clears the cached AssetBundles containing the assets identified by a key along with any bundles containing those assets' dependencies.
译:如果要清除Addressables缓存的任何AssetBundles,请调用Addressables.ClearDependencyCacheAsync。此函数清除包含由键标识的资产以及包含这些资产依赖项的任何Bundle的缓存AssetBundle。
Note that ClearDependencyCacheAsync only clears assets bundles related to the specified key. If you updated the content catalog such that the key no longer exists or it no longer depends on the same AssetBundles, then these no-longer-referenced bundles remain in the cache until they expire (based on cache settings).
译:请注意,ClearDependencyCacheAsync仅清除与指定键相关的资产包。如果您更新了内容目录,使该键不再存在或不再依赖于相同的AssetBundles,则这些不再引用的包将保留在缓存中,直到它们过期(基于缓存设置)。
To clear all AssetBundles, you can use functions in the UnityEngine.Caching class.
译:要清除所有AssetBundles,您可以使用UnityEngine.Caching类中的函数。