包含此页的版本:
不含此页的版本:
要从远程服务器下载 AssetBundle,您可以使用UnityWebRequest.GetAssetBundle.此函数将数据流式传输到内部缓冲区,该缓冲区在工作线程上解码和解压缩 AssetBundle 的数据。
该函数的参数有多种形式。在最简单的形式中,它仅获取应从中下载 AssetBundle 的 URL。您可以选择提供校验和来验证下载数据的完整性。
或者,如果您希望使用 AssetBundle 缓存系统,则可以提供版本号或 Hash128 数据结构。这些与版本号或Hash128 objects通过WWW.LoadFromCacheOrDownload.
UnityWebRequest并将目标 URL 设置为提供的 URL 参数。它还将 HTTP 动词设置为GET,但不设置其他标志或自定义标头。DownloadHandlerAssetBundle到UnityWebRequest.此下载处理程序具有特殊的assetBundle属性,一旦下载和解码了足够的数据以允许访问 AssetBundle 中的资源,它就可用于提取 AssetBundle。Hash128object 作为参数,它还将这些参数传递给DownloadHandlerAssetBundle.然后,下载处理程序使用缓存系统。using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class MyBehaviour : MonoBehaviour {
void Start() {
StartCoroutine(GetAssetBundle());
}
IEnumerator GetAssetBundle() {
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle("https://www.my-server.com/myData.unity3d");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) {
Debug.Log(www.error);
}
else {
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
}
}
}