Created
June 14, 2015 05:38
-
-
Save kazuooooo/92f942d8d2ec49b658a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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