DownloadHandlerAssetBundleConstructor

Switch to Manual
public DownloadHandlerAssetBundle (string url, uint crc);

Parameters

url资源捆绑包所在的名义上的(预重定向)URL。
crc校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。

Description

用于非缓存资源捆绑包的标准构造函数。

此构造函数将绕过缓存系统,直接从 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); } } }

public DownloadHandlerAssetBundle (string url, uint version, uint crc);

Parameters

url资源捆绑包所在的名义上的(预重定向)URL。
crc校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。
version资源捆绑包在 url 的当前版本号。版本号在重复下载时增加。

Description

简单的版本控制构造函数。缓存下载的资源捆绑包。

使用此构造函数时,DownloadHandlerAssetBundle 将首先检查是否有来自 url 的缓存 AssetBundle

如果没有缓存的资源捆绑包,或者如果缓存的资源捆绑包的 versionversion 参数相匹配,则系统将跳过下载此资源捆绑包,改为从缓存中加载它。

如果有缓存的资源捆绑包,但缓存捆绑包的 versionversion 参数不匹配,则系统将从 url 重新下载此资源捆绑包。

如果 crc 参数不是零,则 crc 参数将与下载的数据的校验和做比较。如果 CRC 不匹配,系统将记录一个错误且不加载资源捆绑包,assetBundle 将返回 null

如果不想使用 CRC 完整性检查,可将 crc 参数设置为零。


public DownloadHandlerAssetBundle (string url, Hash128 hash, uint crc);

Parameters

url资源捆绑包所在的名义上的(预重定向)URL。
crc校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。
hash用于定义资源捆绑包版本的哈希对象。

Description

版本控制构造函数。缓存下载的资源捆绑包。

使用此构造函数时,DownloadHandlerAssetBundle 将首先检查是否有来自 url 的缓存 AssetBundle

如果没有缓存的资源捆绑包,或者如果缓存的资源捆绑包的 hashhash 参数相匹配,则系统将跳过下载此资源捆绑包,改为从缓存中加载它。

如果有缓存的资源捆绑包,但缓存捆绑包的 hashhash 参数不匹配,则系统将从 url 重新下载此资源捆绑包。

如果 crc 参数不是零,则 crc 参数将与下载的数据的校验和做比较。如果 CRC 不匹配,系统将记录一个错误且不加载资源捆绑包,assetBundle 将返回 null

如果不想使用 CRC 完整性检查,可将 crc 参数设置为零。


public DownloadHandlerAssetBundle (string url, string name, Hash128 hash, uint crc);
public DownloadHandlerAssetBundle (string url, CachedAssetBundle cachedBundle, uint crc);

Parameters

url资源捆绑包所在的名义上的(预重定向)URL。
hash用于定义资源捆绑包版本的哈希对象。
crc校验和,用于与下载的数据做比较以进行完整性检查;当此参数为零时,将跳过完整性检查。
cachedBundle用于将给定版本的资源捆绑包下载到自定义缓存路径的结构。
name用作自定义缓存路径的 AssetBundle 名称。

Description

Versioned constructor. Caches downloaded asset bundles to a customized cache path.

缓存的资源包仅由文件名和版本唯一标识。缓存过程将忽略 url 中的所有域和路径信息。由于缓存的资源捆绑包由文件名而非完整的 URL 标识,您可以随时更改资源捆绑包的下载目录。这对于推出新版本游戏并确保浏览器或 CDN 不会错误地缓存文件非常有用。

Usually using the filename of the AssetBundle to generate the cache path is fine. But if there are different AssetBundles with the same last file name, cache conflicts happens. With CachedAssetBundle struct, you can use CachedAssetBundle.name to customized the cache path to avoid the cache conflicts. You can also utilize this to organize the cache data structure.