Tools(二)——BytesAdd

来源:互联网 发布:福州 java 编辑:程序博客网 时间:2024/06/06 02:24
依然是Assets/Scripts/Tools/Editor目录下BytesAdd.cs这个文件的代码有错,估计没使用了,又没改吧。
using UnityEngine;using UnityEditor;using System.IO;using System.Collections;public class BytesAdd{    ////这个函数实际上需要选择一个文件夹,    //这函数就是打包选中的文件夹下的所有文件(包括meta)    //但是里面的path很有问题    //这函数不改了,也改不了    [@MenuItem("BoLong/Build  AssetBundles/From bytes of Files")]    static void ExportAssetBundles(){        //这里返回的是相对项目文件夹的路径        //例如:Assets/MyTextures/hello.png        string path = AssetDatabase.GetAssetPath(Selection.activeObject);        BuildAssetBundleOptions option = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;//资源包编译选项        if(path.Length !=0 )        {            path = path.Replace("Assets/","");            //获取目录下的所有文件,不递归            string [] fileEntries = Directory.GetFiles(Application.dataPath + "/" + path);            foreach(string fileName in fileEntries){                string filePath = fileName;                     int index = filePath.LastIndexOf("/");                //这里filePath变成这样子了:                //  /Materials\111.mat.bytes                filePath = filePath.Substring(index);                int indexp = path.LastIndexOf("/");                //这里这path是外部变量,减着减着就没了,就会报错                //如果只执行一次的话,就是获取path文件夹所有在目录                path = path.Substring(0,indexp);                //这又重新把 Assets/加上去,上面已经减去过了                string localPath = "Assets/" + path;                if(index > 0)                {                    localPath += filePath;                }                Object t =AssetDatabase.LoadMainAssetAtPath(localPath);                if(t != null)                {                     string bundlepath = "Assets/" + path + "/" +t.name + ".bytes";                    BuildPipeline.BuildAssetBundle(t,null,bundlepath, option);                }            }            }    }}
阅读全文
0 0