Example #1
0
        public AssetsItem Clone()
        {
            AssetsItem item = new AssetsItem();

            item.AssetBundleName = AssetBundleName;
            item.paths           = copy(paths);
            return(item);
        }
        /**
         * 添加AssetBundle的Item对象
         * */
        private void addABHandler(object target)
        {
            menuParams m     = (menuParams)target;
            AssetsItem asset = new AssetsItem();

            asset.AssetBundleName = m.name;
            asset.VariantName     = 0;
            Parent.list.list.Add(asset);
            Parent.regsList = null;
        }
Example #3
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");
            // 渲染一个可滚动的List
            Parent.scrollPos = EditorGUILayout.BeginScrollView(Parent.scrollPos, GUILayout.Width(Parent.position.width - 12), GUILayout.Height(200));
            // assetbundle列表
            if (Parent.list == null)
            {
                Parent.list = new ReorderableList(Parent.data.items, typeof(AssetsItem), false, false, true, true);
            }
            // 绘制Item显示列表
            Parent.list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                AssetsItem element = Parent.list.list[index] as AssetsItem;
                rect.y += 2;
                EditorGUI.LabelField(new Rect(rect.x, rect.y, 40, EditorGUIUtility.singleLineHeight), "Name:");
                EditorGUI.TextField(new Rect(rect.x + 45, rect.y, rect.width - 45 - 60, EditorGUIUtility.singleLineHeight), element.AssetBundleName);
                EditorGUI.BeginChangeCheck();
                element.VariantName = EditorGUI.Popup(new Rect(rect.width - 50, rect.y, 60, EditorGUIUtility.singleLineHeight), element.VariantName, Parent.data.Variants.ToArray());
                if (EditorGUI.EndChangeCheck())
                {
                    Parent.regsList = null;
                }
            };
            // 绘制表头
            Parent.list.drawHeaderCallback = (Rect rect) => {
                EditorGUI.LabelField(rect, "AssetBundleList");
            };
            // 删除一个assetbundle
            Parent.list.onRemoveCallback = (ReorderableList l) => {
                l.list.RemoveAt(l.index);
                l.index         = 0;
                Parent.regsList = null;
            };
            // 选择回调
            Parent.list.onSelectCallback = (ReorderableList l) => {
                Parent.regsList = null;
            };
            // 添加事件
            Parent.list.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => {
                var menu = new GenericMenu();
                Dictionary <string, int> hash = new Dictionary <string, int>();
                for (int i = 0; i < Parent.data.items.Count; i++)
                {
                    hash[Parent.data.items[i].AssetBundleName] = 0;
                }
                for (int i = 0; i < Parent.data.AssetBunldeName.Count; i++)
                {
                    if (hash.ContainsKey(Parent.data.AssetBunldeName[i]) == false)
                    {
                        menu.AddItem(new GUIContent(Parent.data.AssetBunldeName[i]), false, addABHandler, new menuParams()
                        {
                            name = Parent.data.AssetBunldeName[i]
                        });
                    }
                }
                menu.ShowAsContext();
            };
            Parent.list.DoLayoutList();
            EditorGUILayout.EndScrollView();

            EditorGUILayout.EndVertical();
        }
        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();
        }