Пример #1
0
    /// <summary>
    /// 打包方法;通过配置文件打包;xml中一个大的item就是一个包
    /// </summary>
    private void BuildAssetBundle(AssetBundleEntity entity)
    {
        AssetBundleBuild[] arrBuild = new AssetBundleBuild[1];

        AssetBundleBuild build = new AssetBundleBuild();

        //包名
        build.assetBundleName = string.Format("{0}.{1}", entity.Name, (entity.Tag.Equals("Scene", StringComparison.CurrentCultureIgnoreCase) ? "unity3d" : "assetbundle"));

        //资源路径
        build.assetNames = entity.PathList.ToArray();

        arrBuild[0] = build;

        //目标路径
        string toPath = Application.dataPath + "/../AssetBundles/" + arrBuildTarget[buildTargetIndex] + entity.ToPath;

        //如果目标路径不存在则创建该路径
        if (!Directory.Exists(toPath))
        {
            Directory.CreateDirectory(toPath);
        }

        BuildPipeline.BuildAssetBundles(toPath, arrBuild, BuildAssetBundleOptions.None, target);
    }
Пример #2
0
    /// <summary>
    /// 返回xml数据
    /// </summary>
    /// <returns></returns>
    public List <AssetBundleEntity> GetList()
    {
        m_List.Clear();

        //读取xml 把数据添加到m_List里边
        XDocument xDoc = XDocument.Load(m_Path);
        XElement  root = xDoc.Root;

        XElement assetBundleNode = root.Element("AssetBundle");

        IEnumerable <XElement> lst = assetBundleNode.Elements("Item");

        int index = 0;

        foreach (XElement item in lst)
        {
            AssetBundleEntity entity = new AssetBundleEntity();
            entity.Key         = "key" + ++index;
            entity.Name        = item.Attribute("Name").Value;
            entity.Tag         = item.Attribute("Tag").Value;
            entity.IsFolder    = item.Attribute("IsFolder").Value.Equals("True", System.StringComparison.CurrentCultureIgnoreCase);
            entity.IsFirstData = item.Attribute("IsFirstData").Value.Equals("True", System.StringComparison.CurrentCultureIgnoreCase);


            IEnumerable <XElement> pathList = item.Elements("Path");
            foreach (XElement path in pathList)
            {
                entity.PathList.Add(path.Attribute("Value").Value);
            }

            m_List.Add(entity);
        }
        return(m_List);
    }
Пример #3
0
    public List <AssetBundleEntity> GetList()
    {
        m_List.Clear();

        XDocument doc    = XDocument.Load(m_Path);
        XElement  root   = doc.Root;
        XElement  abNode = root.Element("AssetBundle");

        int index = 0;

        foreach (XElement item in abNode.Elements("Item"))
        {
            AssetBundleEntity entity = new AssetBundleEntity();
            entity.Key     = "key" + ++index;
            entity.Name    = item.Attribute("Name").Value;
            entity.Tag     = item.Attribute("Tag").Value;
            entity.Version = item.Attribute("Version").Value.ToInt();
            entity.Size    = item.Attribute("Size").Value.ToLong();
            entity.ToPath  = item.Attribute("ToPath").Value;

            foreach (XElement path in item.Elements("Path"))
            {
                entity.PathList.Add(String.Format("Assets/{0}", path.Attribute("Value").Value));
            }
            m_List.Add(entity);
        }

        return(m_List);
    }
Пример #4
0
    /// <summary>
    /// 打包方法
    /// </summary>
    /// <param name="entity"></param>
    private void BuildAssetBundle(AssetBundleEntity entity)
    {
        AssetBundleBuild[] arrBuild = new AssetBundleBuild[1];
        AssetBundleBuild   build    = new AssetBundleBuild();

        //包名及后缀
        build.assetBundleName = string.Format("{0}. {1}", entity.Name, (entity.Tag.Equals("Scence", StringComparison.CurrentCultureIgnoreCase) ? "unity3d" : "assetbundle"));
        //AssetBundle包的后缀名...写成下面两行代码会报错,放到上面就不会报错
        //string variant = (entity.Tag.Equals("Scence", StringComparison.CurrentCultureIgnoreCase) ? "unity3d" : "assetbundle");
        //build.assetBundleVariant = variant;


        //资源路径
        build.assetNames = entity.PathList.ToArray();

        arrBuild[0] = build;
        //资源打包保存路径
        string toPath = Application.dataPath + "/../AssetBundle/" + arrBuidTarget[buildTargetIndex] + entity.ToPath;

        //如果目标不存在,则创建文件夹
        if (!Directory.Exists(toPath))
        {
            Directory.CreateDirectory(toPath);
        }
        //四个参数是按照第二个参数的格式来打包,第二个参数保存的是AssetBundle打包的名字、后缀、源文件地址等
        BuildPipeline.BuildAssetBundles(toPath, arrBuild, BuildAssetBundleOptions.None, target);
    }
Пример #5
0
    /// <summary>
    /// 读XML,把XML中配置的资源添加到list集合中
    /// </summary>
    /// <returns></returns>
    public List <AssetBundleEntity> GetList()
    {
        mList.Clear();
        //获取一个XML文件,参数为路径
        XDocument Xdoc = XDocument.Load(mPath);
        //获取这个XML的根节点
        XElement root = Xdoc.Root;
        //从根节点下找一个叫“AssetBundle”的节点
        XElement assetBundleNode = root.Element("AssetBundle");
        //从“AssetBundle”节点下找所有的“Item”节点,返回一个集合
        IEnumerable <XElement> itemList = assetBundleNode.Elements("Item");
        int itemKey = 0;

        foreach (XElement item in itemList)
        {
            //创建实体,为每个属性赋值
            AssetBundleEntity entity = new AssetBundleEntity();
            entity.key         = "LeoTestAB" + itemKey++;
            entity.Name        = item.Attribute("Name").Value;
            entity.Tag         = item.Attribute("Tag").Value;
            entity.IsFolder    = item.Attribute("IsFolder").Value.Equals("true");
            entity.IsFirstData = item.Attribute("IsFirstData").Value.Equals("true");

            //item下的子标签path,也用集合的形式循环获取
            IEnumerable <XElement> pathList = item.Elements("Path");
            foreach (var path in pathList)
            {
                //Assets/后面是资源的路径,
                entity.pathList.Add(string.Format("{0}", path.Attribute("LocalPath").Value));
            }
            mList.Add(entity);
        }

        return(mList);
    }
Пример #6
0
    /// <summary>
    /// 返回XML数据
    /// </summary>
    /// <returns></returns>
    public List <AssetBundleEntity> GetList()
    {
        mList.Clear();

        //读取XML
        XDocument XDoc = XDocument.Load(mPath);

        XElement root = XDoc.Root;

        XElement assetBundleNode = root.Element("AssetBundle");

        IEnumerable <XElement> lst = assetBundleNode.Elements("Item");

        int index = 0;

        foreach (XElement item in lst)
        {
            AssetBundleEntity entity = new AssetBundleEntity();
            entity.Key     = "key" + ++index;
            entity.Name    = item.Attribute("Name").Value;
            entity.Tag     = item.Attribute("Tag").Value;
            entity.Version = item.Attribute("Version").Value.ToInt();
            entity.Size    = item.Attribute("Size").Value.ToLong();
            entity.ToPath  = item.Attribute("ToPath").Value;

            IEnumerable <XElement> pathList = item.Elements("Path");

            foreach (XElement path in pathList)
            {
                entity.PathList.Add(string.Format("Assets/{0}", path.Attribute("Value").Value));
            }
            mList.Add(entity);
        }
        return(mList);
    }
Пример #7
0
    /// <summary>
    /// 保存设置
    /// </summary>
    private void OnSaveSettingCallBack()
    {
        //需要打包的对象
        List <AssetBundleEntity> lst = new List <AssetBundleEntity>();

        foreach (AssetBundleEntity entity in m_List)
        {
            if (m_Dic[entity.Key])
            {
                entity.IsChecked = true;
                lst.Add(entity);
            }
            else
            {
                entity.IsChecked = false;
                lst.Add(entity);
            }
        }

        //循环设置文件夹包括子文件里边的项
        for (int i = 0; i < lst.Count; i++)
        {
            AssetBundleEntity entity = lst[i];//取到一个节点
            if (entity.IsFolder)
            {
                //如果这个节点配置的是一个文件夹,那么需要遍历文件夹
                //需要把路变成绝对路径
                string[] folderArr = new string[entity.PathList.Count];
                for (int j = 0; j < entity.PathList.Count; j++)
                {
                    folderArr[j] = Application.dataPath + "/" + entity.PathList[j];
                }
                SaveFolderSettings(folderArr, !entity.IsChecked);
            }
            else
            {
                //如果不是文件夹 只需要设置里边的项
                string[] folderArr = new string[entity.PathList.Count];
                for (int j = 0; j < entity.PathList.Count; j++)
                {
                    folderArr[j] = Application.dataPath + "/" + entity.PathList[j];
                    SaveFileSetting(folderArr[j], !entity.IsChecked);
                }
            }
        }

        AssetDatabase.RemoveUnusedAssetBundleNames();
        AssetDatabase.Refresh();
        Debug.Log("保存设置完毕");
    }
Пример #8
0
    /// <summary> 保存设置回调 </summary>
    private void OnSaveAssetBundleCallBack()
    {
        //需要打包的对象
        List <AssetBundleEntity> list = new List <AssetBundleEntity>();

        foreach (AssetBundleEntity entity in m_List)
        {
            if (m_Dic[entity.Key])
            {
                entity.IsChecked = true;
                list.Add(entity);
            }
            else
            {
                entity.IsChecked = false;
                list.Add(entity);
            }
        }
        //循环设置文件夹(包括子文件夹里面的项)
        for (int i = 0; i < list.Count; i++)
        {
            AssetBundleEntity entity = list[i];

            if (entity.IsFolder)
            {
                //如果这个节点配置是一个文件夹,那么需要遍历文件夹
                //需要把路径变成绝对路径
                string[] folderArr = new string[entity.PathList.Count];
                for (int k = 0; k < entity.PathList.Count; k++)
                {
                    folderArr[k] = Application.dataPath + "/" + entity.PathList[k];
                }
                SaveFolderSettings(folderArr, !entity.IsChecked);
            }
            else
            {
                //如果不是文件夹只需要设置里面的项
                string[] arrFiles = new string[entity.PathList.Count];
                for (int k = 0; k < entity.PathList.Count; k++)
                {
                    arrFiles[k] = Application.dataPath + "/" + entity.PathList[k];
                    SaveFileSetting(arrFiles[k], !entity.IsChecked);
                }
            }
        }
    }
Пример #9
0
    private void BuildAssetBundle(AssetBundleEntity entity)
    {
        AssetBundleBuild[] builds = new AssetBundleBuild[1];
        //包名
        Debug.Log(entity.Name + entity.Tag);
        builds[0].assetBundleName    = entity.Name; //string.Format("{0}.{1}", entity.Name, entity.Tag.Equals("Scene",StringComparison.CurrentCultureIgnoreCase) ? "Unity3d" : "assetBundle");
        builds[0].assetBundleVariant = entity.Tag.Equals("Scene", StringComparison.CurrentCultureIgnoreCase) ? "Unity3d" : "assetBundle";
        builds[0].assetNames         = entity.PathList.ToArray();
        string abOutDir = Application.dataPath + "/../Assetbundles/" + arrayBuildTarget[m_buildIndexTarget] + "/" + entity.ToPath;

        if (!Directory.Exists(abOutDir))
        {
            Directory.CreateDirectory(abOutDir);
        }

        BuildPipeline.BuildAssetBundles(abOutDir, builds, BuildAssetBundleOptions.None, target);
    }
Пример #10
0
    /// <summary>
    /// 打AB包具体实现过程
    /// </summary>
    /// <param name="entity"></param>
    public void BuildAssetBundleOld(AssetBundleEntity entity)
    {
        AssetBundleBuild[] abBuild = new AssetBundleBuild[1];
        AssetBundleBuild   build   = new AssetBundleBuild();

        build.assetBundleName    = entity.Name;
        build.assetBundleVariant = (entity.Tag == "Scene") ? "unity3d" : "assetbundle"; //资源后缀
        build.assetNames         = entity.pathList.ToArray();                           //资源路径
        string toPath = Application.dataPath + "/../AssetBundles/" + mBuildTarget[buildTargetIndex];

        //string toPath = "";
        abBuild[0] = build; //build参数设置完毕后给数组赋值
        if (!Directory.Exists(toPath))
        {
            Directory.CreateDirectory(toPath);
        }
        BuildPipeline.BuildAssetBundles(toPath, abBuild, BuildAssetBundleOptions.None, buildTarget);
    }
Пример #11
0
    private void BuildAssetBundle(AssetBundleEntity entity)
    {
        AssetBundleBuild[] arrBuilds = new AssetBundleBuild[1];
        AssetBundleBuild   build     = new AssetBundleBuild();

        build.assetBundleName = String.Format("{0}.{1}", entity.Name, entity.Tag.Equals("Scene", StringComparison.CurrentCultureIgnoreCase) ? "unity3d" : "assetbundle");
        build.assetNames      = entity.PathList.ToArray();

        arrBuilds[0] = build;
        string toPath = Application.dataPath + "/../AssetBundles/" + arrBuildTarget[buildTargetIndex] + entity.ToPath;

        if (!Directory.Exists(toPath))
        {
            Directory.CreateDirectory(toPath);
        }

        BuildPipeline.BuildAssetBundles(toPath, arrBuilds, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
    }
Пример #12
0
    /// <summary>
    /// 保存设置回调
    /// </summary>
    private void OnSaveAssetBundleCallBack()
    {
        List <AssetBundleEntity> listNeedBuild = new List <AssetBundleEntity>();

        foreach (AssetBundleEntity entity in m_List)
        {
            if (m_Dic[entity.Key])
            {
                entity.IsChecked = true;
                listNeedBuild.Add(entity);
            }
            else
            {
                entity.IsChecked = false;
                listNeedBuild.Add(entity);
            }
        }
        for (int i = 0; i < listNeedBuild.Count; ++i)
        {
            AssetBundleEntity entity = listNeedBuild[i];
            if (entity.IsFolder)
            {
                string[] folderArr = new string[entity.PathList.Count];
                for (int j = 0; j < folderArr.Length; ++j)
                {
                    folderArr[j] = Application.dataPath + "/" + entity.PathList[j];
                }
                SaveFolderSettings(folderArr, !entity.IsChecked);
            }
            else
            {
                string[] FileArr = new string[entity.PathList.Count];
                for (int j = 0; j < FileArr.Length; ++j)
                {
                    FileArr[j] = Application.dataPath + "/" + entity.PathList[j];
                    SaveFileBundleNameAndVariant(FileArr[j], !entity.IsChecked);
                }
            }
        }
        this.ShowNotification(new GUIContent("保存设置完成"));
        Debug.Log("保存设置完成");
    }
Пример #13
0
    private void OnSaveConfigCallback()
    {
        List <AssetBundleEntity> list = new List <AssetBundleEntity>();

        foreach (AssetBundleEntity entity in mList)
        {
            if (mDic[entity.key])
            {
                entity.IsChecked = true;
                list.Add(entity);
            }
            else
            {
                entity.IsChecked = false;
                list.Add(entity);
            }
        }
        //循环为AB资源分类
        for (int i = 0; i < list.Count; i++)
        {
            AssetBundleEntity entity = list[i];
            if (entity.IsFolder)    //如果是文件夹,则遍历里面的所有项,需要转换成绝对路径
            {
                string[] folders = new string[entity.pathList.Count];
                for (int j = 0; j < folders.Length; j++)
                {
                    folders[j] = Application.dataPath + "/" + entity.pathList[j];   //组合一个绝对路径
                }
                SaveFolderSettings(folders, !entity.IsChecked);
            }
            else    //不是文件夹,则直接操作此项
            {
                string[] folders = new string[entity.pathList.Count];
                for (int j = 0; j < folders.Length; j++)
                {
                    folders[j] = Application.dataPath + "/" + entity.pathList[j];   //组合一个绝对路径
                    SaveFileSettings(folders[j], !entity.IsChecked);
                }
            }
        }
    }
Пример #14
0
    private void AnalyzeXML(string path)
    {
        if (!string.IsNullOrEmpty(path))
        {
            try
            {
                XDocument document              = XDocument.Load(path);
                XElement  root                  = document.Root;
                XElement  assetBundleNode       = root.Element("AssetBundle");
                IEnumerable <XElement> elements = assetBundleNode.Elements();
                int index = 100;
                foreach (XElement item in elements)
                {
                    AssetBundleEntity entity = new AssetBundleEntity();
                    entity.Key     = index++.ToString();
                    entity.Name    = item.Attribute(XName.Get("Name")).Value;
                    entity.Tag     = item.Attribute(XName.Get("Tag")).Value;
                    entity.Version = item.Attribute(XName.Get("Version")).Value.ToInt();
                    entity.Size    = item.Attribute(XName.Get("Size")).Value.ToLong();
                    entity.ToPath  = item.Attribute(XName.Get("ToPath")).Value;

                    IEnumerable <XElement> pathList = item.Elements("Path");
                    foreach (XElement node in pathList)
                    {
                        entity.PathList.Add(node.Attribute(XName.Get("Value")).Value);
                    }
                    m_list.Add(entity);
                }
            }
            catch (System.Exception e)
            {
                Debug.Log(e.Message);
            }
        }
        else
        {
            Debug.LogError(GetType() + "/AnalyzeXML()/xml路径非法? path=" + path);
            return;
        }
    }
Пример #15
0
    /// <summary>
    /// 返回xml数据(m_List 集合)
    /// </summary>
    /// <returns></returns>
    public List <AssetBundleEntity> GetList()
    {
        //返回前先清空
        m_List.Clear();

        //======================读取xml 把数据添加到m_List里

        //将xml数据读成XDocument对象
        XDocument xDoc = XDocument.Load(m_Path);
        XElement  root = xDoc.Root;

        XElement assetBundleNode = root.Element("AssetBundle");

        IEnumerable <XElement> lst = assetBundleNode.Elements("Item");

        int index = 0;

        //编辑器模式中可以使用foreach
        foreach (XElement item in lst)
        {
            AssetBundleEntity entity = new AssetBundleEntity();
            entity.Key     = "key" + ++index;
            entity.Name    = item.Attribute("Name").Value;
            entity.Tag     = item.Attribute("Tag").Value;
            entity.Version = item.Attribute("Version").Value.ToInt();
            entity.Size    = item.Attribute("Size").Value.ToLong();
            entity.ToPath  = item.Attribute("ToPath").Value;

            IEnumerable <XElement> pathList = item.Elements("Path");
            foreach (XElement path in pathList)
            {
                entity.PathList.Add(string.Format("Assets/{0}", path.Attribute("Value").Value));
            }

            m_List.Add(entity);
        }

        return(m_List);
    }
Пример #16
0
    /// <summary>
    /// 资源包加密
    /// </summary>
    /// <param name="path"></param>
    private void AssetBundleEncrypt(bool isDelete = false)
    {
        //循环设置文件夹包括子文件里边的项
        for (int i = 0; i < m_List.Count; i++)
        {
            AssetBundleEntity entity = m_List[i];//取到一个节点

            if (entity.IsEncrypt)
            {
                string[] folderArr = new string[entity.PathList.Count];
                for (int j = 0; j < entity.PathList.Count; j++)
                {
                    string path = Application.dataPath + "/../AssetBundles/" + dal.GetVersion() + "/" + arrBuildTarget[buildTargetIndex] + "/" + entity.PathList[j];

                    if (entity.IsFolder == false)
                    {
                        //不是遍历文件夹打包 说明这个路径就是一个包
                        path = path + ".assetbundle";

                        AssetBundleEncryptFile(path, isDelete);
                    }
                    else
                    {
                        AssetBundleEncryptFolder(path, isDelete);
                    }
                }
            }
        }

        if (isDelete)
        {
            Debug.Log("删除加密资源包完毕");
        }
        else
        {
            Debug.Log("资源包加密完毕");
        }
    }
Пример #17
0
    void OnGUI()
    {
        if (mList == null)
        {
            return;
        }
        #region 第一行 按钮
        GUILayout.BeginHorizontal("box");

        selectTypeIndex = EditorGUILayout.Popup(typeIndex, mType, GUILayout.Width(100));
        //选择后立即勾选
        if (selectTypeIndex != typeIndex)
        {
            typeIndex = selectTypeIndex;
            EditorApplication.delayCall = OnTypeIndexCallback;  //选完某个type后立即执行打钩操作
        }

        /*
         * if (GUILayout.Button("选择资源类型", GUILayout.Width(150)))
         * {
         *  //EditorApplication.delayCall = OnTypeIndexCallback;
         *  Debug.Log("已弃用!选择后立即打勾");
         * }
         */
        //选择后立即切换
        selectBuildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, mBuildTarget, GUILayout.Width(100));
        if (selectBuildTargetIndex != buildTargetIndex)
        {
            buildTargetIndex            = selectBuildTargetIndex;
            EditorApplication.delayCall = OnTargetIndexCallback;
        }

        /*
         * if (GUILayout.Button("选择平台", GUILayout.Width(150)))
         * {
         *  //EditorApplication.delayCall = OnTargetIndexCallback;
         *  Debug.Log("已弃用!选择后立即打勾");
         * }
         */
        if (GUILayout.Button("开始AB标签分类", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnSaveConfigCallback;
        }

        if (GUILayout.Button("开始打AB包", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnCreateABCallback;
        }

        if (GUILayout.Button("清空AB包", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnClearABCallback;
        }
        if (GUILayout.Button("拷贝本地配置文件表", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnCopyDataTableCallBack;
        }
        if (GUILayout.Button("生成版本文件", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnCreateVersionFileCallBack;
        }
        EditorGUILayout.Space();
        GUILayout.EndHorizontal();
        #endregion

        #region 第二行 AB资源标题
        GUILayout.BeginHorizontal("box");
        GUILayout.Label("  ", GUILayout.Width(20));
        GUILayout.Label("Pkg_Name", GUILayout.Width(200));
        GUILayout.Label("Tag", GUILayout.Width(100));
        GUILayout.Label("IsFolder", GUILayout.Width(200));
        GUILayout.Label("IsFirstData", GUILayout.Width(200));
        GUILayout.EndHorizontal();

        #endregion

        #region 第三行开始 具体的AB资源信息
        GUILayout.BeginVertical();
        pos = GUILayout.BeginScrollView(pos);
        for (int i = 0; i < mDic.Count; i++)
        {
            AssetBundleEntity entity = mList[i];
            GUILayout.BeginHorizontal("box");

            mDic[entity.key] = GUILayout.Toggle(mDic[entity.key], "", GUILayout.Width(20));
            GUILayout.Label(entity.Name, GUILayout.Width(200));
            GUILayout.Label(entity.Tag, GUILayout.Width(100));
            GUILayout.Label(entity.IsFolder.ToString(), GUILayout.Width(200));
            GUILayout.Label(entity.IsFirstData.ToString(), GUILayout.Width(100));
            // GUILayout.Label(entity.Size.ToString(), GUILayout.Width(100));
            GUILayout.EndHorizontal();

            foreach (string path in entity.pathList)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Space(40);
                GUILayout.Label(path);
                GUILayout.EndHorizontal();
            }
        }
        GUILayout.EndScrollView();
        GUILayout.EndVertical();


        #endregion
    }
Пример #18
0
    /// <summary>
    /// 绘制窗口
    /// </summary>
    void OnGUI()
    {
        if (m_List == null)
        {
            return;
        }

        #region  钮行
        GUILayout.BeginHorizontal("box");

        //绘制下拉菜单,选择Tag
        tagIndex = EditorGUILayout.Popup(tagIndex, arrTag, GUILayout.Width(100));
        if (GUILayout.Button("选定Tag", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnSelectTagCallBack;
        }

        //绘制下拉菜单,选择打包平台
        buildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, arrBuildTarget, GUILayout.Width(100));
        if (GUILayout.Button("选定Target", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnSelectTargetCallBack;
        }

        if (GUILayout.Button("打AssetBundle包", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnAssetBundleCallBack;
        }

        if (GUILayout.Button("清空AssetBundle包", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnClearAssetBundleCallBack;
        }

        //加空格,使横行绘制完全
        EditorGUILayout.Space();

        GUILayout.EndHorizontal();
        #endregion

        #region 标题
        GUILayout.BeginHorizontal("box");
        GUILayout.Label("包名");
        GUILayout.Label("标记", GUILayout.Width(100));
        GUILayout.Label("保存路径", GUILayout.Width(200));
        GUILayout.Label("版本", GUILayout.Width(100));
        GUILayout.Label("大小", GUILayout.Width(100));
        GUILayout.EndHorizontal();
        #endregion

        #region 内容
        GUILayout.BeginVertical();
        //开启滚动视图
        pos = EditorGUILayout.BeginScrollView(pos);

        //循环项
        for (int i = 0; i < m_List.Count; i++)
        {
            AssetBundleEntity entity = m_List[i];

            GUILayout.BeginHorizontal("box");

            //复选框
            m_Dic[entity.Key] = GUILayout.Toggle(m_Dic[entity.Key], "", GUILayout.Width(20));

            GUILayout.Label(entity.Name);
            GUILayout.Label(entity.Tag, GUILayout.Width(100));
            GUILayout.Label(entity.ToPath, GUILayout.Width(200));
            GUILayout.Label(entity.Version.ToString(), GUILayout.Width(100));
            GUILayout.Label(entity.Size.ToString(), GUILayout.Width(100));

            GUILayout.EndHorizontal();

            foreach (string path in entity.PathList)
            {
                GUILayout.BeginHorizontal("box");
                //40宽度空格
                GUILayout.Space(40);
                //绘制路径
                GUILayout.Label(path);
                GUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.EndScrollView();

        GUILayout.EndVertical();

        #endregion
    }
Пример #19
0
    private void OnGUI()
    {
        if (m_List == null)
        {
            return;
        }
        #region ------ 按钮行 ------
        GUILayout.BeginHorizontal("Box");
        selectTagIndex = EditorGUILayout.Popup(tagIndex, arrTag, GUILayout.Width(100));
        if (selectTagIndex != tagIndex)
        {
            tagIndex = selectTagIndex;
            EditorApplication.delayCall = OnSelectTagCallBack;
        }
        selectBuildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, arrBuilTarget, GUILayout.Width(100));
        if (selectBuildTargetIndex != buildTargetIndex)
        {
            buildTargetIndex            = selectBuildTargetIndex;
            EditorApplication.delayCall = OnSelectTargetCallBack;
        }
        if (GUILayout.Button("清空AssetBundle", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnClearAssetBundleCallBack;
        }

        if (GUILayout.Button("保存设置", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnSaveAssetBundleCallBack;
        }
        if (GUILayout.Button("打AssetBundle包", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnCreateAssetBundleCallBack;
        }
        if (GUILayout.Button("拷贝数据表", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnCopyDataTableCallBack;
        }
        if (GUILayout.Button("生成版本文件", GUILayout.Width(150)))
        {
            EditorApplication.delayCall = OnCreateVersionTextCallBack;
        }
        EditorGUILayout.Space();
        GUILayout.EndHorizontal();
        #endregion

        GUILayout.BeginHorizontal("box");
        GUILayout.Label("包名");
        GUILayout.Label("标记", GUILayout.Width(100));
        GUILayout.Label("文件夹", GUILayout.Width(200));
        GUILayout.Label("初始资源", GUILayout.Width(200));
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical();

        pos = GUILayout.BeginScrollView(pos);

        for (int i = 0; i < m_List.Count; i++)
        {
            AssetBundleEntity entity = m_List[i];
            GUILayout.BeginHorizontal("box");

            m_Dic[entity.Key] = GUILayout.Toggle(m_Dic[entity.Key], "", GUILayout.Width(20));
            GUILayout.Label(entity.Name);
            GUILayout.Label(entity.Tag, GUILayout.Width(100));
            GUILayout.Label(entity.IsFolder.ToString(), GUILayout.Width(200));
            GUILayout.Label(entity.IsFirstData.ToString(), GUILayout.Width(200));
            GUILayout.EndHorizontal();

            foreach (var path in entity.PathList)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Space(40);
                GUILayout.Label(path);
                GUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.EndScrollView();
        GUILayout.EndVertical();
    }
Пример #20
0
    /// <summary>
    /// 生成依赖关系文件
    /// </summary>
    private void OnCreateDependenciesFile()
    {
        //第一次循环 把所有的Asset存储到一个列表里

        //临时列表
        List <AssetEntity> tempLst = new List <AssetEntity>();

        //循环设置文件夹包括子文件里边的项
        for (int i = 0; i < m_List.Count; i++)
        {
            AssetBundleEntity entity = m_List[i];//取到一个节点

            string[] folderArr = new string[entity.PathList.Count];
            for (int j = 0; j < entity.PathList.Count; j++)
            {
                string path = Application.dataPath + "/" + entity.PathList[j];
                //Debug.LogError("path=" + path);
                CollectFileInfo(tempLst, path);
            }
        }

        //
        int len = tempLst.Count;

        //资源列表
        List <AssetEntity> assetList = new List <AssetEntity>();

        for (int i = 0; i < len; i++)
        {
            AssetEntity entity = tempLst[i];

            AssetEntity newEntity = new AssetEntity();
            newEntity.Category        = entity.Category;
            newEntity.AssetName       = entity.AssetFullName.Substring(entity.AssetFullName.LastIndexOf("/") + 1);
            newEntity.AssetName       = newEntity.AssetName.Substring(0, newEntity.AssetName.LastIndexOf("."));
            newEntity.AssetFullName   = entity.AssetFullName;
            newEntity.AssetBundleName = entity.AssetBundleName;

            assetList.Add(newEntity);

            //场景不需要检查依赖项
            if (entity.Category == AssetCategory.Scenes)
            {
                continue;
            }

            newEntity.DependsAssetList = new List <AssetDependsEntity>();

            string[] arr = AssetDatabase.GetDependencies(entity.AssetFullName);
            foreach (string str in arr)
            {
                if (!str.Equals(newEntity.AssetFullName, StringComparison.CurrentCultureIgnoreCase) && GetIsAsset(tempLst, str))
                {
                    AssetDependsEntity assetDepends = new AssetDependsEntity();
                    assetDepends.Category      = GetAssetCategory(str);
                    assetDepends.AssetFullName = str;

                    //把依赖资源 加入到依赖资源列表
                    newEntity.DependsAssetList.Add(assetDepends);
                }
            }
        }

        //生成一个Json文件
        string targetPath = Application.dataPath + "/../AssetBundles/" + dal.GetVersion() + "/" + arrBuildTarget[buildTargetIndex];

        if (!Directory.Exists(targetPath))
        {
            Directory.CreateDirectory(targetPath);
        }

        string strJsonFilePath = targetPath + "/AssetInfo.json"; //版本文件路径

        IOUtil.CreateTextFile(strJsonFilePath, LitJson.JsonMapper.ToJson(assetList));
        Debug.Log("生成 AssetInfo.json 完毕");

        MMO_MemoryStream ms = new MMO_MemoryStream();

        //生成二进制文件
        len = assetList.Count;
        ms.WriteInt(len);

        for (int i = 0; i < len; i++)
        {
            AssetEntity entity = assetList[i];
            ms.WriteByte((byte)entity.Category);
            ms.WriteUTF8String(entity.AssetFullName);
            ms.WriteUTF8String(entity.AssetBundleName);

            if (entity.DependsAssetList != null)
            {
                //添加依赖资源
                int depLen = entity.DependsAssetList.Count;
                ms.WriteInt(depLen);
                for (int j = 0; j < depLen; j++)
                {
                    AssetDependsEntity assetDepends = entity.DependsAssetList[j];
                    ms.WriteByte((byte)assetDepends.Category);
                    ms.WriteUTF8String(assetDepends.AssetFullName);
                }
            }
            else
            {
                ms.WriteInt(0);
            }
        }

        string filePath = targetPath + "/AssetInfo.bytes"; //版本文件路径

        byte[] buffer = ms.ToArray();
        buffer = ZlibHelper.CompressBytes(buffer);
        FileStream fs = new FileStream(filePath, FileMode.Create);

        fs.Write(buffer, 0, buffer.Length);
        fs.Close();
        fs.Dispose();
        Debug.Log("生成 AssetInfo.bytes 完毕");
    }
Пример #21
0
    /// <summary>
    /// 绘制窗口
    /// </summary>
    void OnGUI()
    {
        if (m_List == null)
        {
            return;
        }

        #region  钮行
        GUILayout.BeginHorizontal("box");

        selectBuildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, arrBuildTarget, GUILayout.Width(100));
        if (selectBuildTargetIndex != buildTargetIndex)
        {
            buildTargetIndex            = selectBuildTargetIndex;
            EditorApplication.delayCall = OnSelectTargetCallBack;
        }

        if (GUILayout.Button("保存设置", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnSaveSettingCallBack;
        }

        if (GUILayout.Button("清空设置", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnClearSettingCallBack;
        }

        if (GUILayout.Button("清空AssetBundle包", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnClearAssetBundleCallBack;
        }

        if (GUILayout.Button("打AssetBundle包", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnAssetBundleCallBack;
        }

        if (GUILayout.Button("升级资源版本号(" + dal.GetVersion() + ")", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnUpdateVersionCallBack;
        }

        EditorGUILayout.Space();
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal("box");

        if (GUILayout.Button("生成 AssetInfo.bytes", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnCreateDependenciesFile;
        }

        if (GUILayout.Button("生成版本文件", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnCreateVersionFileCallBack;
        }

        EditorGUILayout.Space();

        GUILayout.EndHorizontal();
        #endregion

        GUILayout.BeginHorizontal("box");
        GUILayout.Label("包名");
        GUILayout.Label("标记", GUILayout.Width(100));
        GUILayout.Label("文件夹", GUILayout.Width(200));
        GUILayout.Label("初始资源", GUILayout.Width(200));
        GUILayout.Label("是否加密", GUILayout.Width(220));
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical();

        pos = EditorGUILayout.BeginScrollView(pos);

        for (int i = 0; i < m_List.Count; i++)
        {
            AssetBundleEntity entity = m_List[i];

            GUILayout.BeginHorizontal("box");

            m_Dic[entity.Key] = GUILayout.Toggle(m_Dic[entity.Key], "", GUILayout.Width(20));
            GUILayout.Label(entity.Name);
            GUILayout.Label(entity.Tag, GUILayout.Width(100));
            GUILayout.Label(entity.IsFolder.ToString(), GUILayout.Width(200));
            GUILayout.Label(entity.IsFirstData.ToString(), GUILayout.Width(200));
            GUILayout.Label(entity.IsEncrypt.ToString(), GUILayout.Width(200));
            GUILayout.EndHorizontal();

            foreach (string path in entity.PathList)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Space(40);
                GUILayout.Label(path);
                GUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.EndScrollView();

        GUILayout.EndVertical();
    }
Пример #22
0
    /// <summary>
    /// 绘制窗口
    /// </summary>
    public void OnGUI()
    {
        while (IsRun)
        {
            string path = Application.dataPath + "/Editor/AssetBundle/AssetBundleConfig.xml";
            dal   = new AssetBundleDAL(path);
            mList = dal.GetList();
            mDic  = new Dictionary <string, bool>();
            for (int i = 0; i < mList.Count; i++)
            {
                mDic[mList[i].Key] = true;
            }
            IsRun = false;
            break;
        }
        if (mList == null)
        {
            return;
        }
        #region  钮行
        EditorGUILayout.BeginHorizontal("box");
        //新建一个下拉列表
        tagIndex = EditorGUILayout.Popup(tagIndex, arrTag, GUILayout.Width(100));
        //创建一个按钮
        if (GUILayout.Button("选定Tag", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnSelectTagCallBack;
        }
        //新建一个下拉列表
        buildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, arrBuidTarget, GUILayout.Width(100));
        if (GUILayout.Button("选定Target", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnSelectTargetCallBack;
        }
        if (GUILayout.Button("打AssetBundle包", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnAssetBundleCallBack;
        }
        if (GUILayout.Button("清空AssetBundle包", GUILayout.Width(200)))
        {
            EditorApplication.delayCall = OnClearAssetBundleCallBack;
        }
        EditorGUILayout.Space();//用空白自动填充剩余的部分

        EditorGUILayout.EndHorizontal();
        #endregion
        #region 显示包内容
        GUILayout.BeginHorizontal("BOX");
        GUILayout.Label("包名");
        GUILayout.Label("标记", GUILayout.Width(100));
        GUILayout.Label("保存路径", GUILayout.Width(200));
        GUILayout.Label("版本", GUILayout.Width(100));
        GUILayout.Label("大小", GUILayout.Width(100));
        GUILayout.EndHorizontal();
        #endregion

        GUILayout.BeginVertical();

        pos = EditorGUILayout.BeginScrollView(pos);

        for (int i = 0; i < mList.Count; i++)
        {
            AssetBundleEntity entity = mList[i];
            GUILayout.BeginHorizontal("box");
            mDic[entity.Key] = GUILayout.Toggle(mDic[entity.Key], "", GUILayout.Width(20));
            GUILayout.Label(entity.Name);
            GUILayout.Label(entity.Tag, GUILayout.Width(100));
            GUILayout.Label(entity.ToPath, GUILayout.Width(200));
            GUILayout.Label(entity.Version.ToString(), GUILayout.Width(100));
            GUILayout.Label(entity.Size.ToString(), GUILayout.Width(100));
            GUILayout.EndHorizontal();
            foreach (string path in entity.PathList)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Space(40);
                GUILayout.Label(path);
                GUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.EndScrollView();

        GUILayout.EndVertical();
    }
Пример #23
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal("Box");

        selectTagIndex = EditorGUILayout.Popup(tagIndex, arrTag, GUILayout.Width(100));
        if (selectTagIndex != tagIndex)
        {
            tagIndex = selectTagIndex;
            EditorApplication.delayCall = OnSelectTagCallBack;
        }

        selectBuildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, arrBuildTarget, GUILayout.Width(100));
        if (selectBuildTargetIndex != buildTargetIndex)
        {
            buildTargetIndex            = selectBuildTargetIndex;
            EditorApplication.delayCall = OnSelectBuildTargetCallBack;
        }

        selectGameIndex = EditorGUILayout.Popup(gameIndex, arrGame, GUILayout.Width(100));
        if (selectGameIndex != gameIndex)
        {
            gameIndex = selectGameIndex;
            EditorApplication.delayCall = OnSelectGameCallBack;
        }

        if (GUILayout.Button("保存设置", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnSaveAssetBundleCallBack;
        }

        if (GUILayout.Button("打包", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnBuildAssetBundleCallBack;
        }

        if (GUILayout.Button("清空", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnClearAssetBundleCallBack;
        }

        if (GUILayout.Button("拷贝数据表", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnCopyDataTableCallBack;
        }

        if (GUILayout.Button("生成版本文件", GUILayout.Width(100)))
        {
            EditorApplication.delayCall = OnCreateVersionInfoCallBack;
        }


        GUILayout.EndHorizontal();



        GUILayout.BeginHorizontal("Box");

        GUILayout.Label("包名");
        GUILayout.Label("所属游戏", GUILayout.Width(100));
        GUILayout.Label("标记", GUILayout.Width(100));
        GUILayout.Label("是否文件夹", GUILayout.Width(100));
        GUILayout.Label("是否初始资源", GUILayout.Width(100));

        GUILayout.EndHorizontal();



        GUILayout.BeginVertical();

        if (m_List == null)
        {
            return;
        }
        pos = EditorGUILayout.BeginScrollView(pos);

        for (int i = 0; i < m_List.Count; ++i)
        {
            AssetBundleEntity entity = m_List[i];
            GUILayout.BeginHorizontal();

            m_Dic[entity.Key] = GUILayout.Toggle(m_Dic[entity.Key], "", GUILayout.Width(100));

            GUILayout.Label(entity.Name);
            GUILayout.Label(entity.Game, GUILayout.Width(100));
            GUILayout.Label(entity.Tag, GUILayout.Width(100));
            GUILayout.Label(entity.IsFolder.ToString(), GUILayout.Width(100));
            GUILayout.Label(entity.IsFirstData.ToString(), GUILayout.Width(100));
            GUILayout.EndHorizontal();

            foreach (string path in entity.PathList)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Space(40);

                GUILayout.Label(path);
                GUILayout.EndHorizontal();
            }
        }
        EditorGUILayout.EndScrollView();
        GUILayout.EndVertical();
    }