//Build打包设置
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class CreateAssetBundle {
[MenuItem ("Assets/Build AssetBundle")]
static void BuildAssetBundle(){
string dir = "AssetBundles";
//判断路径是否存在,不存在创建一个
if (Directory.Exists(dir)==false) {
Directory.CreateDirectory (dir);
}
//BuildAssetBundles(第一个参数是路径,第二个默认选择None,第三个选择Build平台)
BuildPipeline.BuildAssetBundles (dir,BuildAssetBundleOptions.None,BuildTarget.StandaloneWindows64);
}
}
using UnityEngine;
using System.Collections;
public class LoadFormFileExample : MonoBehaviour {
//1.本地加载AssetBundle包
//本地加载时候可以把加载进去的bundle加载出来 但是不能接着做成预制体,因为会丢失材质
void Start () {
//AssetBundle.LoadFromFile(路径名字);
AssetBundle ab = AssetBundle.LoadFromFile ("AssetBundles/uirootassetbundle");
//加载Prefab的名字注意是打包时候Prefab在unity工程里面的名字
GameObject uiRoot = ab.LoadAsset<GameObject> ("UI Root");
//实例化
Instantiate (uiRoot);
}