load Assetbundle

using UnityEngine;
using System.Collections;

public class ZYLOAdAssetBundle : MonoBehaviour {

 

//不同平台下StreamingAssets的路径是不同的,这里需要注意一下。
public static readonly string PathURL =
#if UNITY_ANDROID
"jar:file://" + Application.dataPath + "!/assets/";
#elif UNITY_IPHONE
Application.dataPath + "/Raw/";
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR
"file://" + Application.dataPath + "/StreamingAssets/";
#else
string.Empty;
#endif

 

void OnGUI()
{
if (GUILayout.Button("ThisAssetbundle"))
{
//StartCoroutine(LoadMainGameObject(Application.dataPath + "/StreamingAssets/" + "Capsule.assetbundle"));
StartCoroutine(LoadMainGameObject("http://192.168.0.98/MyItems/MyCard/Capsule.assetbundle"));
}
}

//读取一个资源

private IEnumerator LoadMainGameObject(string path)
{
WWW bundle = new WWW(path);

yield return bundle;

//加载到游戏中
yield return Instantiate(bundle.assetBundle.mainAsset);

bundle.assetBundle.Unload(false);
}

}

posted @ 2016-06-27 10:01  Fei非非  阅读(224)  评论(0编辑  收藏  举报