Version: 2022.3
言語: 日本語
public static Networking.UnityWebRequest GetAssetBundle (string uri);
public static Networking.UnityWebRequest GetAssetBundle (Uri uri);
public static Networking.UnityWebRequest GetAssetBundle (string uri, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (Uri uri, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (string uri, uint version, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (Uri uri, uint version, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (string uri, Hash128 hash, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (Uri uri, Hash128 hash, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (string uri, CachedAssetBundle cachedAssetBundle, uint crc);
public static Networking.UnityWebRequest GetAssetBundle (Uri uri, CachedAssetBundle cachedAssetBundle, uint crc);

パラメーター

uri ダウンロードするアセットバンドルの URI
crc この数字がゼロでない場合、ダウンロードしたアセットバンドルデータのチェックサムと比較されます。 CRC が一致しない場合はエラーがログに記録され、アセットバンドルはロードされません。0 にセットすると CRC チェックはスキップされます。
version ダウンロードするアセットバンドルのキャッシュされたバージョンと比較する整数の Version Number です。 Unity がキャッシュしているアセットのバンドルを再ダウンロードすると強制的にこの番号をインクリメントします。

WWW.LoadFromCacheOrDownload の version パラメーターに似ています。
hash バージョンのハッシュです。このハッシュがこのアセットバンドルのキャッシュされたバージョンのハッシュと一致しない場合、アセットバンドルは再度ダウンロードされます。
cachedAssetBundle A structure used to download a given version of AssetBundle to a customized cache path.

戻り値

UnityWebRequest UnityWebRequest は Unity Asset Bundle をダウンロードするように設定されます。

説明

HTTP GET 経由で Unity Asset Bundle をダウンロードするために最適化された UnityWebRequest を作成します。

このメソッドは UnityWebRequest を作成します。メソッドを GET にセットし、ストリングの引数 uri に対象の URL をセットします。他のフラグまたはカスタムヘッダーはセットされません。

このメソッドは DownloadHandlerAssetBundleUnityWebRequest にアタッチします。 DownloadHandler は特別な DownloadHandlerAssetBundle.assetBundle プロパティーを持ち、十分なデータがダウンロードされているアセットバンドルを抽出するのに使用でき、バンドル内のリソースへのアクセスを許可するようにデコードされます。

また、リングバッファーの中へ DownloadHandlerAssetBundle ストリームデータを入れ、ワーカースレッドでデータを復元させることでデータのすべてを一度にダウンロードするのに比べて多くのメモリ割り当てを少なくできます。

整数型 version または Hash128 hash 引数で指定されている場合、DownloadHandlerAssetBundle は Asset Bundle キャッシングシステムを採用します。 Asset Bundle がキャッシュされて再度ダウンロードする必要がない場合、一度、Asset Bundle のキャッシュからのロードを終了させて UnityWebRequest を完了します。

Cached AssetBundles are uniquely identified solely by the filename and version. All domain and path information in url is ignored by Caching. Since cached AssetBundles are identified by filename instead of the full URL, you can change the directory from where the asset bundle is downloaded at any time. This is useful for pushing out new versions of the game and ensuring that files are not cached incorrectly by the browser or by a 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.

Note, that while you can use this API to load Asset Bundle from local storage (using file:// URI or jar:file// on Android), this is not recommended, use AssetBundle.LoadFromFileAsync instead.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MyBehaviour : MonoBehaviour { void Start() { StartCoroutine(GetText()); }

IEnumerator GetText() { using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("https://www.my-server.com/mybundle")) { yield return uwr.SendWebRequest();

if (uwr.result != UnityWebRequest.Result.Success) { Debug.Log(uwr.error); } else { // Get downloaded asset bundle AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); } } } }