using UnityEngine;
using System.Collections;
//
using UnityEditor;
// CreateAssetBundle
public class CreateAssetBundle :MonoBehaviour
{
[MenuItem("Assets/Build AssetBundle Scene")]
static void BuildAssetBundle()
{
string sceneName = "Assets/Scenes/taotao.unity";
BuildPipeline.BuildPlayer(sceneName, Application.dataPath + "/StreamingAssets/Scenes/taotao.unity3d",
BuildTarget.StandaloneWindows64, BuildOptions.BuildAdditionalStreamedScenes);
AssetDatabase.Refresh();
}
}
using UnityEngine;
using System.Collections;
// LoadAssetBundles
public class LoadAssetBundles :MonoBehaviour
{
private stirng m_Url;
private string m_AssetName;
public void LoadBundle(string name)
{
// 可以执行file的 path
m_Url = "file://" + Application.dataPath + "/StreamingAssets/" + name + ".unity3d";
// web读取路径
m_Url = Application.dataPath + "/StreamingAssets/" + name + ".unity3d";
m_AssetName = name;
StartCoroutine(DownLoad());
}
IEnumerator DownLoad()
{
WWW www = new WWW(m_Url);
yield return www;
if(www.error != null)
Debug.LogError("下载场景失败:" + www.error);
else{
AssetBundle bundle = www.assetBundle;
Application.LoadLevel(m_AssetName);
Debug.LogError(“跳转场景!”);
bundle.Unload(false);
}
www.Dispose();
}
}