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

Unity_Addressable_AssetBundle Loading(加载AB包)

2023-04-12 09:39 作者:unity_某某师_高锦锦  | 我要投稿

AssetBundle Loading

The Addressables system packs your assets in AssetBundles and loads these bundles "behind the scenes" as you load individual assets. You can control how AssetBundles load which are exposed on the BundledAssetGroupSchema class. You can set these options through the scripting API or under the Advanced options in the inspector of the AddressablesAssetGroup inspector.

译:Addressables系统将您的资产打包在AssetBundles中,并在加载单个资产时“幕后”加载这些包。您可以控制AssetBundles如何加载,这些选项在BundledAssetGroupSchema类中公开。您可以通过脚本API或在AddressablesAssetGroup检查器的高级选项下设置这些选项。

UnityWebRequestForLocalBundles

Addressables can load AssetBundles via two engine APIs: UnityWebRequest.GetAssetBundle, and AssetBundle.LoadFromFileAsync. The default behavior is to use AssetBundle.LoadFromFileAsync when the AssetBundle is in local storage and use UnityWebRequest when the AssetBundle path is a URL.

译:Addressables可以通过两个引擎API加载AssetBundles:UnityWebRequest.GetAssetBundle和AssetBundle.LoadFromFileAsync。默认情况下,当AssetBundle位于本地存储中时,使用AssetBundle.LoadFromFileAsync,当AssetBundle路径为URL时,则使用UnityWebRequest。

You can override this behavior to use UnityWebRequest for local Asset Bundles by setting BundledAssetGroupSchema.UseUnityWebRequestForLocalBundles to true. It can also be set through the BundledAssetGroupSchema GUI.

译:您可以通过将BundledAssetGroupSchema.UseUnityWebRequestForLocalBundles设置为true来覆盖此行为,以便在本地Asset Bundle上使用UnityWebRequest。也可以通过BundledAssetGroupSchema GUI进行设置。

A few of these situations would include:

译:以下是几种这样的情况:

  1. You are shipping local AssetBundles that use LZMA compression because you want your shipped game package to be as small as possible. In this case, you would want to use UnityWebRequest to recompress those AssetBundles LZ4 into the local disk cache.译:您正在发布使用LZMA压缩的本地AssetBundles,因为想要使您的游戏程序包尽可能小。在这种情况下,您希望使用UnityWebRequest将这些AssetBundles LZ4重新压缩到本地磁盘缓存中。

  2. You are shipping an Android game and your APK contains AssetBundles that are compressed with the default APK compression.译: 您正在发行Android游戏,您的APK包含使用默认APK压缩的AssetBundles。

  3. You want the entire local AssetBundle to be loaded into memory to avoid disk seeks. If you use UnityWebRequest and have caching disabled, the entire AssetBundle file will be loaded into the memory cache. This increases your runtime memory usage, but may improve loading performance as it eliminates disk seeking after the initial AssetBundle load. Both situations 1 and 2 above result in the AssetBundle existing on the player device twice (original and cached representations). This means the initial loads (decompressing and copying to cache) are slower than subsequent loads (loading from cache)译:您正在发布使用LZMA压缩的本地AssetBundles,因为想要使您的游戏程序包尽可能小。在这种情况下,您希望使用UnityWebRequest将这些AssetBundles LZ4重新压缩到本地磁盘缓存中。 您正在发行Android游戏,您的APK包含使用默认APK压缩的AssetBundles。 您希望将整个本地AssetBundle加载到内存中,以避免磁盘寻道。如果使用UnityWebRequest并禁用缓存,则整个AssetBundle文件将加载到内存缓存中。这会增加您的运行时内存使用,但可能会提高加载性能,因为它消除了初始AssetBundle加载后的磁盘寻道。上述两种情况1和2都导致AssetBundle在播放器设备上存在两次(原始表示和缓存表示)。这意味着初始加载(解压缩并复制到缓存)比后续加载(从缓存中加载)慢。

Handling Download Errors

When a download fails, the RemoteProviderException contains errors that can be used to determine how to handle the failure. The RemoteProviderException is either the AsyncOperationHandle.OperationException or an inner exception. As shown below:

译:当下载失败时,RemoteProviderException包含错误信息,可用于确定如何处理该失败。RemoteProviderException是AsyncOperationHandle.OperationException或内部异常之一。如下所示:

Possible error strings:

译:

  • "Request aborted"译:"请求已中止"

  • "Unable to write data"译:"无法写入数据" 

  • "Malformed URL"译:"URL格式错误" 

  • "Out of memory"译:"内存不足" 

  • "No Internet Connection"译:"无网络连接" 

  • "Encountered invalid redirect (missing Location header?)"译:"遇到无效的重定向(缺少Location标头?)" 

  • "Cannot modify request at this time"译:"此时无法修改请求" 

  • "Unsupported Protocol"译:"不支持的协议" 

  • "Destination host has an erroneous SSL certificate"译:"目标主机具有错误的SSL证书" 

  • "Unable to load SSL Cipher for verification"译:"无法加载SSL密码进行验证" 

  • "SSL CA certificate error"译:"SSL CA证书错误" 

  • "Unrecognized content-encoding"译:"未识别的内容编码" 

  • "Request already transmitted"译:"请求已经传输" "

  • "Invalid HTTP Method"译:HTTP方法无效" 

  • "Header name contains invalid characters"译:"标头名称包含无效字符" 

  • "Header value contains invalid characters"译:"标头值包含无效字符" 

  • "Cannot override system-specified headers"译:"无法覆盖系统指定的标头" 

  • "Backend Initialization Error"译:"后端初始化错误" 

  • "Cannot resolve proxy"译:"无法解析代理"

  • "Cannot resolve destination host"译: "无法解析目标主机" 

  • "Cannot connect to destination host"译:"无法连接到目标主机" 

  • "Access denied"译:"访问被拒绝" 

  • "Generic/unknown HTTP error"译:"常规/未知HTTP错误" 

  • "Unable to read data"译:"无法读取数据" 

  • "Request timeout"译:"请求超时" 

  • "Error during HTTP POST transmission"译:"在HTTP POST传输期间发生错误" 

  • "Unable to complete SSL connection"译:"无法完成SSL连接"

  • "Redirect limit exceeded"译: "重定向限制已超出" 

  • "Received no data in response"译:"没有收到响应数据" "

  • "Destination host does not support SSL"译:目标主机不支持SSL" 

  • "Failed to transmit data"译:"传输数据失败" 

  • "Failed to receive data"译:"接收数据失败" "

  • "Login failed"译:登录失败" 

  • "SSL shutdown failed"译: "SSL关闭失败"

  • "Redirect limit is invalid"译:"重定向限制无效"

  • "Not implemented"译:"未实现"

  • "Data Processing Error, see Download Handler error"译:"数据处理错误,请参阅下载处理程序错误"

  • "Unknown Error"译: "未知错误"



Unity_Addressable_AssetBundle Loading(加载AB包)的评论 (共 条)

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