Version: 6000.3
语言: 中文
从 HTTP 服务器 (GET) 检索纹理
将表单发送到 HTTP 服务器 (POST)

从 HTTP 服务器 (GET) 下载 AssetBundle

要从远程服务器下载 AssetBundle,您可以使用UnityWebRequest.GetAssetBundle.此函数将数据流式传输到内部缓冲区,该缓冲区在工作线程上解码和解压缩 AssetBundle 的数据。

该函数的参数有多种形式。在最简单的形式中,它仅获取应从中下载 AssetBundle 的 URL。您可以选择提供校验和来验证下载数据的完整性。

或者,如果您希望使用 AssetBundle 缓存系统,则可以提供版本号或 Hash128 数据结构。这些与版本号或Hash128 objects通过WWW.LoadFromCacheOrDownload.

  • 此函数创建了一个UnityWebRequest并将目标 URL 设置为提供的 URL 参数。它还将 HTTP 动词设置为GET,但不设置其他标志或自定义标头。
  • 此函数附加一个DownloadHandlerAssetBundleUnityWebRequest.此下载处理程序具有特殊的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);
        }
    }
}
从 HTTP 服务器 (GET) 检索纹理
将表单发送到 HTTP 服务器 (POST)