Пример #1
0
        // 绘制所有的item分类
        private void DrawingList(string titleName, PathList pl)
        {
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical("Box");
            if (scrollDict.ContainsKey(titleName) == false)
            {
                scrollDict.Add(titleName, new Vector2());
            }
            scrollDict[titleName] = EditorGUILayout.BeginScrollView(scrollDict[titleName], GUILayout.Width(Parent.position.width - 12), GUILayout.Height(200));

            ReorderableList list;

            if (rlist.ContainsKey(titleName) == false)
            {
                // 初始化列表
                files.Add(titleName, new List <string>());
                for (int i = 0; i < pl.psList.Count; i++)
                {
                    Dictionary <string, int> f = DirectorytUtility.getPathFiles(pl.psList[i].path, pl.psList[i].assetRegexType);
                    foreach (KeyValuePair <string, int> kv in f)
                    {
                        if (files[titleName].IndexOf(kv.Key) == -1)
                        {
                            files[titleName].Add(kv.Key);
                        }
                    }
                }

                list = new ReorderableList(files[titleName], typeof(string), false, false, false, false);
                rlist.Add(titleName, list);
            }
            else
            {
                list = rlist[titleName];
            }

            // 绘制表头
            list.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, titleName);
            };
            // 渲染element
            list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                EditorGUI.TextField(rect, "path:", (string)list.list[index]);
            };

            list.DoLayoutList();
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
Пример #2
0
        /**
         * 检测配置文件的正确性
         * */
        public static Dictionary <string, List <string> > CheckFilesOver(AssetBundleData data)
        {
            // 文件地址&&对应的列表
            Dictionary <string, List <string> > checkData = new Dictionary <string, List <string> >();

            // 所有的配置列表
            for (int i = 0; i < data.items.Count; i++)
            {
                AssetsItem item = data.items[i];

                foreach (KeyValuePair <string, PathList> kvp in item.paths)
                {
                    string   key   = kvp.Key;
                    PathList paths = item.paths[key];
                    for (int n = 0; n < paths.psList.Count; n++)
                    {
                        // 目录下包含内容的规则
                        PathStruct ps = paths.psList[n];
                        Dictionary <string, int> files = DirectorytUtility.getPathFiles(ps.path, ps.assetRegexType);
                        foreach (var kv in files)
                        {
                            if (checkData.ContainsKey(kv.Key) == false)
                            {
                                checkData.Add(kv.Key, new List <string>()
                                {
                                    item.AssetBundleName
                                });
                            }
                            else
                            {
                                checkData[kv.Key].Add(item.AssetBundleName);
                            }
                        }
                    }
                }
            }
            return(checkData);
        }
        public override void Drawing()
        {
            if (Parent.data == null)
            {
                return;
            }
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical("Box");
            Parent.regScrollPos = EditorGUILayout.BeginScrollView(Parent.regScrollPos, GUILayout.Width(Parent.position.width - 12), GUILayout.Height(200));
            // 没有初始化过list
            if (Parent.regsList == null)
            {
                // asset选择过,并且数据列表不为空
                if (Parent.list.index >= 0 && Parent.data.items.Count > 0)
                {
                    AssetsItem items = Parent.data.items[Parent.list.index];
                    if (items.paths.ContainsKey(Parent.data.Variants[items.VariantName]) == false)
                    {
                        items.paths.Add(Parent.data.Variants[items.VariantName], new PathList());
                    }

                    Parent.regsList = new ReorderableList(items.paths[Parent.data.Variants[items.VariantName]].psList, typeof(PathStruct), false, false, false, true);
                }
                else
                {
                    List <PathStruct> createList = new List <PathStruct>();
                    Parent.regsList = new ReorderableList(createList, typeof(PathStruct), false, false, false, true);
                }
            }
            // 绘制表头
            Parent.regsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Assets Path");
            };
            // 渲染element
            Parent.regsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                PathStruct ps = Parent.regsList.list[index] as PathStruct;
                EditorGUI.LabelField(new Rect(rect.x, rect.y + 2, 40, EditorGUIUtility.singleLineHeight), "Path:");
                EditorGUI.TextField(new Rect(rect.x + 45, rect.y + 2, rect.width - 45 - 60, EditorGUIUtility.singleLineHeight), ps.path);
                ps.assetRegexType = (AssetRegexType)EditorGUI.EnumMaskField(new Rect(rect.width - 50, rect.y + 2, 60, EditorGUIUtility.singleLineHeight), (AssetRegexType)ps.assetRegexType);
            };
            // 删除
            Parent.regsList.onRemoveCallback = (ReorderableList l) => {
                l.list.RemoveAt(l.index);
                l.index = -1;
            };
            Parent.regsList.DoLayoutList();
            DropProc();

            EditorGUILayout.EndScrollView();
            //检查打包内容是否选的nothing
            for (int i = 0; i < Parent.regsList.list.Count; i++)
            {
                PathStruct ps = Parent.regsList.list[i] as PathStruct;;

                if ((int)ps.assetRegexType == 0)
                {
                    EditorGUILayout.HelpBox("RegexType is nothing ", MessageType.Error);
                }
            }


            if (GUILayout.Button("Applied Programe"))
            {
                // 将当前的配置方案应用到项目
                Dictionary <string, List <string> > dict = BundleUtility.CheckFilesOver(Parent.data);
                bool pass = true;
                foreach (KeyValuePair <string, List <string> > kvp in dict)
                {
                    if (kvp.Value.Count > 1)
                    {
                        // 说明存在重复
                        for (int i = 0; i < kvp.Value.Count; i++)
                        {
                            pass = false;
                            Debug.LogError("file path:" + kvp.Key + "    AssetBundle:" + kvp.Value[i]);
                        }
                    }
                }
                if (pass == false)
                {
                    return;
                }

                // 通过检测,开始配置数据
                if (Parent.data.items.Count > 0)
                {
                    for (int n = 0; n < Parent.data.items.Count; n++)
                    {
                        AssetsItem items   = Parent.data.items[n];
                        string     variant = string.Empty;
                        if (items.VariantName != 0)
                        {
                            variant = Parent.data.Variants[items.VariantName];
                        }
                        foreach (KeyValuePair <string, PathList> m_kvp in items.paths)
                        {
                            string   vkey = m_kvp.Key;
                            PathList pl   = items.paths[vkey];
                            for (int j = 0; j < pl.psList.Count; j++)
                            {
                                PathStruct ps = pl.psList[j];

                                Dictionary <string, int> paths = DirectorytUtility.getPathFiles(ps.path, ps.assetRegexType);
                                foreach (KeyValuePair <string, int> kvp in paths)
                                {
                                    string        pkey = (string)kvp.Key;
                                    AssetImporter ai   = AssetImporter.GetAtPath(pkey);
                                    ai.assetBundleName    = items.AssetBundleName;
                                    ai.assetBundleVariant = variant;
                                }
                            }
                        }
                    }
                    AssetDatabase.RemoveUnusedAssetBundleNames();

                    //成功弹窗
                    EditorUtility.DisplayDialog("Apply success", "Done! ", "ok", null);
                }
            }
            if (GUILayout.Button("Files Show"))
            {
                // 将当前的配置方案应用到项目
                showWindow();
                //BundleUtility.CheckFilesOver(Parent.data);
            }
            EditorGUILayout.EndVertical();
        }