Unity_Addressable_Preloading dependencies(預(yù)加載依賴項(xiàng))
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.
譯:在遠(yuǎn)程分發(fā)內(nèi)容時(shí),有時(shí)可以通過預(yù)先下載應(yīng)用程序需要的依賴項(xiàng)來改善感知性能。例如,您可以在玩家第一次啟動(dòng)游戲時(shí),在啟動(dòng)時(shí)下載必要內(nèi)容,以確保他們不必在游戲過程中等待內(nèi)容。
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鍵所需的所有依賴項(xiàng)都可在已安裝應(yīng)用程序的本地內(nèi)容或下載緩存中使用。
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).
譯:如果您有一組要預(yù)先下載的資產(chǎn),則可以將相同的標(biāo)簽(例如“preload”)分配給這些資產(chǎn),并在調(diào)用Addressables.DownloadDependenciesAsync時(shí)將該標(biāo)簽用作鍵。如果不可用,則Addressables會下載包含具有該標(biāo)簽的資產(chǎn)的所有AssetBundle(以及任何包含資產(chǎn)依賴項(xiàng)的束)。
Progress
An?AsyncOperationHandle?instance provides two ways to get progress:
譯:AsyncOperationHandle實(shí)例提供兩種獲取進(jìn)度的方法:
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 :報(bào)告已完成子操作的百分比。例如,如果一個(gè)操作使用六個(gè)子操作執(zhí)行其任務(wù),則PercentComplete指示當(dāng)其中三個(gè)操作完成時(shí),整個(gè)操作已經(jīng)完成了50%(不管每個(gè)操作加載多少數(shù)據(jù))。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 :返回一個(gè)DownloadStatus結(jié)構(gòu),該結(jié)構(gòu)按照總下載大小報(bào)告百分比。例如,如果操作有六個(gè)子操作,但第一個(gè)操作代表總下載大小的50%,則GetDownloadStatus在第一個(gè)操作完成時(shí)指示操作已經(jīng)完成50%。
The following example illustrates how you could use?GetDownloadStatus?to check the status and dispatch progress events during the download:
譯:以下示例說明了如何使用GetDownloadStatus檢查狀態(tài)并在下載期間調(diào)度進(jìn)度事件:
To discover how much data you need to download in order to load one or more assets, you can call?Addressables.GetDownloadSizeAsync:
譯:要發(fā)現(xiàn)需要下載多少數(shù)據(jù)才能加載一個(gè)或多個(gè)資產(chǎn),您可以調(diào)用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.
譯:完成操作的結(jié)果是必須下載的字節(jié)數(shù)。如果Addressables已經(jīng)緩存了所有必需的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:
譯:在閱讀結(jié)果對象后,始終釋放下載操作句柄。如果您不需要訪問下載操作的結(jié)果,則可以通過將autoReleaseHandle參數(shù)設(shè)置為true來自動(dòng)釋放句柄,如下例所示:
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,請調(diào)用Addressables.ClearDependencyCacheAsync。此函數(shù)清除包含由鍵標(biāo)識的資產(chǎn)以及包含這些資產(chǎn)依賴項(xiàng)的任何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僅清除與指定鍵相關(guān)的資產(chǎn)包。如果您更新了內(nèi)容目錄,使該鍵不再存在或不再依賴于相同的AssetBundles,則這些不再引用的包將保留在緩存中,直到它們過期(基于緩存設(shè)置)。
To clear all AssetBundles, you can use functions in the?UnityEngine.Caching?class.
譯:要清除所有AssetBundles,您可以使用UnityEngine.Caching類中的函數(shù)。