Unity_Addressable_Transforming resource URLs(轉(zhuǎn)換資源URL)
Transforming resource URLs
Addressables provides the following ways to modify the URLs it uses to load assets at runtime:
譯:Addressables提供以下方法來(lái)修改它在運(yùn)行時(shí)用于加載資產(chǎn)的URL:
Static properties in a Profile variable譯:在Profile變量中使用靜態(tài)屬性
Implementing an ID transform function譯:實(shí)現(xiàn)ID轉(zhuǎn)換函數(shù)
Implementing a WebRequestOverride method譯:實(shí)現(xiàn)WebRequestOverride方法
Static Profile variables
You can use a static property when defining the?RemoteLoadPath Profile variable?to specify all or part of the URL from which your application loads remote content, including catalogs, catalog hash files, and AssetBundles. See?Profile variable syntax?for information about specifying a property name in a Profile variable. The value of your static property must be set before Addressables initializes. Changing the value after initialization has no effect.
譯:您可以在定義RemoteLoadPath Profile變量時(shí)使用靜態(tài)屬性,以指定應(yīng)用程序從遠(yuǎn)程內(nèi)容加載的所有或部分URL,包括目錄、目錄哈希文件和AssetBundles。有關(guān)在Profile變量中指定屬性名稱的信息,請(qǐng)參閱Profile變量語(yǔ)法。您的靜態(tài)屬性的值必須在Addressables初始化之前設(shè)置。在初始化后更改值沒有任何效果。
ID transform function
You can assign a function to the?Addressables.ResourceManager?object's?InternalIdTransformFunc?property to individually change the URLs from which Addressables loads assets. You must assign the function before the relevant operation starts, otherwise the default URL is used.
譯:您可以將函數(shù)分配給Addressables.ResourceManager對(duì)象的InternalIdTransformFunc屬性,以逐個(gè)更改Addressables加載資產(chǎn)的URL。否則默認(rèn)的URL將被使用。您必須在相關(guān)操作開始之前分配該函數(shù)。
Using TransformInternalId grants a fair amount of flexibility, especially in regards to remote hosting. Given a single IResourceLocation, you can transform the ID to point towards a server specified at runtime. This is particularly useful if your server IP address changes or if you use different URLS to provide different variants of your application assets..
譯:使用TransformInternalId可以獲得相當(dāng)大的靈活性,尤其是關(guān)于遠(yuǎn)程托管方面。給定單個(gè)IResourceLocation,您可以將ID轉(zhuǎn)換為指向在運(yùn)行時(shí)指定的服務(wù)器。如果您的服務(wù)器IP地址更改或者您使用不同的URL提供應(yīng)用程序資產(chǎn)的不同變體,則這特別有用
The ResourceManager calls your TransformInternalId function when it looks up an asset, passing the?IResourceLocation?instance for the asset to your function. You can change the?InternalId?property of this IResourceLocation and return the modified object to the ResourceManager.
譯:當(dāng)ResourceManager查找資產(chǎn)時(shí),它會(huì)調(diào)用TransformInternalId函數(shù),并將資產(chǎn)的IResourceLocation實(shí)例傳遞給您的函數(shù)。您可以更改此IResourceLocation的InternalId屬性,并返回已修改的對(duì)象以供ResourceManager使用
The following example illustrates how you could append a query string to all URLs for AssetBundles:
譯:以下示例說明了如何將查詢字符串附加到所有AssetBundle的URL:
WebRequest override
You can assign a function to the?Addressables?object's?WebRequestOverride?property to individually modify the?UnityWebRequest?from which is used to download files, such as an AssetBundle or catalog json file. You must assign the function before the relevant operation starts, otherwise the default UnityWebRequest is used.
譯:您可以將函數(shù)分配給Addressables對(duì)象的WebRequestOverride屬性,以單獨(dú)修改用于下載文件(如AssetBundle或目錄JSON文件)的UnityWebRequest。否則將使用默認(rèn)的UnityWebRequest。您必須在相關(guān)操作開始之前分配該函數(shù)
The ResourceManager calls your?WebRequestOverride?function before?UnityWebRequest.SendWebRequest?is called. Passing the UnityWebRequest for the download to your function.
譯:在UnityWebRequest.SendWebRequest被調(diào)用之前,ResourceManager會(huì)調(diào)用您的WebRequestOverride函數(shù),并將下載的UnityWebRequest傳遞給您的函數(shù)
The following example illustrates how you could append a query string to all URLs for AssetBundles and catalogs:
譯:以下示例說明了如何將查詢字符串附加到所有AssetBundle和目錄的URL: