using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;
public class Scene1 : MonoBehaviour {
//创建资源包
[MenuItem("CustomizeTheResource/CreateResource")]
static void ExecCreateAssetBunldes()
{
//设置资源包保存路径
string targetDir = Application.dataPath + "/AssetBundles";
Object[] SelectedAsset = Selection.GetFiltered(typeof(object),SelectionMode.DeepAssets);
//创建一个目录,用于保存资源包
if(!Directory.Exists(targetDir))
{
Directory.CreateDirectory(targetDir);
}
for(int i =0; i < SelectedAsset.Length; i++)
{
//生产资源包的完整路径
string filePath = targetDir + "/" + SelectedAsset[i].name + ".unity3d";
//根据路径判断资源包文件是否存在
if(File.Exists(filePath))
{
//如果存在直接删除它
File.Delete(filePath);
}
//生产新的资源包文件
if(BuildPipeline.BuildAssetBundle(SelectedAsset[i],null,filePath,BuildAssetBundleOptions.CollectDep