Skip to content

Instantly share code, notes, and snippets.

@kazuooooo
Created June 14, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuooooo/92f942d8d2ec49b658a9 to your computer and use it in GitHub Desktop.
Save kazuooooo/92f942d8d2ec49b658a9 to your computer and use it in GitHub Desktop.
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