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

Unity_Addressable_Transforming resource URLs(转换资源URL)

2023-04-11 15:54 作者:unity_某某师_高锦锦  | 我要投稿

Transforming resource URLs

Addressables provides the following ways to modify the URLs it uses to load assets at runtime:

译:Addressables提供以下方法来修改它在运行时用于加载资产的URL:

  • Static properties in a Profile variable译:在Profile变量中使用静态属性

  • Implementing an ID transform function译:实现ID转换函数

  • Implementing a WebRequestOverride method译:实现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变量时使用静态属性,以指定应用程序从远程内容加载的所有或部分URL,包括目录、目录哈希文件和AssetBundles。有关在Profile变量中指定属性名称的信息,请参阅Profile变量语法。您的静态属性的值必须在Addressables初始化之前设置。在初始化后更改值没有任何效果。

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.

译:您可以将函数分配给Addressables.ResourceManager对象的InternalIdTransformFunc属性,以逐个更改Addressables加载资产的URL。否则默认的URL将被使用。您必须在相关操作开始之前分配该函数。

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可以获得相当大的灵活性,尤其是关于远程托管方面。给定单个IResourceLocation,您可以将ID转换为指向在运行时指定的服务器。如果您的服务器IP地址更改或者您使用不同的URL提供应用程序资产的不同变体,则这特别有用

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.

译:当ResourceManager查找资产时,它会调用TransformInternalId函数,并将资产的IResourceLocation实例传递给您的函数。您可以更改此IResourceLocation的InternalId属性,并返回已修改的对象以供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.

译:您可以将函数分配给Addressables对象的WebRequestOverride属性,以单独修改用于下载文件(如AssetBundle或目录JSON文件)的UnityWebRequest。否则将使用默认的UnityWebRequest。您必须在相关操作开始之前分配该函数

The ResourceManager calls your WebRequestOverride function before UnityWebRequest.SendWebRequest is called. Passing the UnityWebRequest for the download to your function.

译:在UnityWebRequest.SendWebRequest被调用之前,ResourceManager会调用您的WebRequestOverride函数,并将下载的UnityWebRequest传递给您的函数

The following example illustrates how you could append a query string to all URLs for AssetBundles and catalogs:

译:以下示例说明了如何将查询字符串附加到所有AssetBundle和目录的URL:




Unity_Addressable_Transforming resource URLs(转换资源URL)的评论 (共 条)

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