using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;
public class Scene1 : MonoBehaviour {
void OnGUI()
{
if(GUILayout.Button("Download psb17"))
{
//下载材质
StartCoroutine(loadBunldMat("psb16"));
}
if(GUILayout.Button("Create Plane"))
{
//克隆物体
StartCoroutine(loadBundleObject("Cube"));
}
}
IEnumerator loadBunldMat(string name)
{
Material mat;
//资源的本机的路径,如果是在服务器上换成相应的api
WWW data = new WWW("file://" + Application.dataPath + "/AssetBundles/" + name + ".unity3d");
//等待下载完成
yield return data;
//下载得到资源文件的转换为材质
mat = (Material)data.assetBundle.mainAsset;
//更换为下载资源
renderer.material = mat;
//释放资源对象
data.assetBundle.Unload(false);
}
IEnumerator loadBundleObject(string name)
{
//资源子啊本机的路径
WWW data = new WWW("file://" + Application.dataPath + "/AssetBundles/" + name +".unity3d");
//等待下载完成
yield return Instantiate(data.assetBundle.mainAsset);
}
}