url | 资源捆绑包所在的名义上的(预重定向)URL。 |
crc | 校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。 |
用于非缓存资源捆绑包的标准构造函数。
此构造函数将绕过缓存系统,直接从 url
下载 AssetBundle。
如果 crc
参数不是零,则 crc
参数将与下载的数据的校验和做比较。如果 CRC 不匹配,系统将记录一个错误且不加载资源捆绑包,assetBundle 将返回 null
。
如果不想使用 CRC 完整性检查,可将 crc
参数设置为零。
using System.Collections; using UnityEngine; using UnityEngine.Networking;
public class Example : MonoBehaviour { IEnumerator Start() { string url = "https://website.com/assetbundle"; using (var uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET)) { uwr.downloadHandler = new DownloadHandlerAssetBundle(url, 0); yield return uwr.SendWebRequest(); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); } } }
url | 资源捆绑包所在的名义上的(预重定向)URL。 |
crc | 校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。 |
version | 资源捆绑包在 url 的当前版本号。版本号在重复下载时增加。 |
简单的版本控制构造函数。缓存下载的资源捆绑包。
使用此构造函数时,DownloadHandlerAssetBundle 将首先检查是否有来自 url
的缓存 AssetBundle。
如果没有缓存的资源捆绑包,或者如果缓存的资源捆绑包的 version
与 version
参数相匹配,则系统将跳过下载此资源捆绑包,改为从缓存中加载它。
如果有缓存的资源捆绑包,但缓存捆绑包的 version
与 version
参数不匹配,则系统将从 url
重新下载此资源捆绑包。
如果 crc
参数不是零,则 crc
参数将与下载的数据的校验和做比较。如果 CRC 不匹配,系统将记录一个错误且不加载资源捆绑包,assetBundle 将返回 null
。
如果不想使用 CRC 完整性检查,可将 crc
参数设置为零。
url | 资源捆绑包所在的名义上的(预重定向)URL。 |
crc | 校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。 |
hash | 用于定义资源捆绑包版本的哈希对象。 |
版本控制构造函数。缓存下载的资源捆绑包。
使用此构造函数时,DownloadHandlerAssetBundle 将首先检查是否有来自 url
的缓存 AssetBundle。
如果没有缓存的资源捆绑包,或者如果缓存的资源捆绑包的 hash
与 hash
参数相匹配,则系统将跳过下载此资源捆绑包,改为从缓存中加载它。
如果有缓存的资源捆绑包,但缓存捆绑包的 hash
与 hash
参数不匹配,则系统将从 url
重新下载此资源捆绑包。
如果 crc
参数不是零,则 crc
参数将与下载的数据的校验和做比较。如果 CRC 不匹配,系统将记录一个错误且不加载资源捆绑包,assetBundle 将返回 null
。
如果不想使用 CRC 完整性检查,可将 crc
参数设置为零。
url | 资源捆绑包所在的名义上的(预重定向)URL。 |
hash | 用于定义资源捆绑包版本的哈希对象。 |
crc | 校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。 |
cachedBundle | 用于将给定版本的资源捆绑包下载到自定义缓存路径的结构。 |
name | 用作自定义缓存路径的 AssetBundle 名称。 |
版本控制构造函数。缓存将资源包下载到自定义的缓存路径。
缓存的资源包仅由文件名和版本唯一标识。缓存过程将忽略 url
中的所有域和路径信息。由于缓存的资源捆绑包由文件名而非完整的 URL 标识,您可以随时更改资源捆绑包的下载目录。这对于推出新版本游戏并确保浏览器或 CDN 不会错误地缓存文件非常有用。
通常情况下,使用 AssetBundle 的文件名生成缓存路径是没有问题的。但如果不同的 AssetBundles 具有相同的最后文件名,则会发生缓存冲突。借助 CachedAssetBundle 结构,您可以使用 CachedAssetBundle.name 来自定义缓存路径,以避免缓存冲突。您还可以利用它来组织缓存数据结构。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.