using UnityEngine;
using System.Collections;
public class testLoadFromAB : MonoBehaviour {
IEnumerator DownloadAndCache()
{
while (!Caching.ready)
yield return null;
//注意,从本地加载时,必须使用前缀 file:///或file://,从网络加载则使用 http://,这两种协议可以在iphone和WINDOWS, 安卓上通用
//UNITY MANUAL:
//http://, https:// and file:// protocols are supported on iPhone.
//ftp:// protocol support is limited to anonymous downloads only. Other protocols are not supported.
WWW www = WWW.LoadFromCacheOrDownload ("file:///Z:/unity/learn-test/Assets/AssetBundles/cubes.unity3d", );
yield return www;
if(!string.IsNullOrEmpty (www.error)){//有些平台不支持string为null,这种写法可以避免意外
Debug.LogError (www.error);
yield break;
}
AssetBundle bundle = www.assetBundle;
//注意必须使用Instantiate实例化出来才能将两个CUBE显示到场景中
GameObject cube1 = Instantiate (bundle.LoadAsset ("DecalCube2")) as GameObject;
GameObject cube2 = Instantiate (bundle.LoadAsset ("DecalCube3")) as GameObject;
}
// Use this for initialization
void Start () {
StartCoroutine ("DownloadAndCache");
}
// Update is called once per frame
void Update () {
}
}