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 をセットします。他のフラグまたはカスタムヘッダーはセットされません。
このメソッドは DownloadHandlerAssetBundle を UnityWebRequest にアタッチします。 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); } } } }
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.