Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using System.Collections;
public class CachingLoadExample : MonoBehaviour
{
public string BundleURL;
public string AssetName;
public int version;
void Start ()
{
StartCoroutine (DownloadAndCache ());
}
IEnumerator DownloadAndCache ()
{
//キャッシュの準備が出来るまで待機
while (!Caching.ready)
yield return null;
//キャッシュに無ければダウンロード
using (WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)) {
yield return www;
//エラーがあれば
if (www.error != null) {
throw new UnityException ("WWW download had an error" + www.error);
}
AssetBundle bundle = www.assetBundle;
if (AssetName == "") {
Instantiate (bundle.mainAsset);
} else {
Instantiate (bundle.LoadAsset (AssetName));
}
//圧縮あ終わったらAssetBundlesをアンロード
bundle.Unload (false);
}
//メモリーがwebstreamから解放(www.Disposeが強制的に呼ばれる)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment