private void OnGUI()
        {
            // 列表显示
            EditorGUILayout.Space();
            EditorGUILayout.LabelField($"Collection List");
            for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Elements.Count; i++)
            {
                string folderPath = AssetBundleCollectorSettingData.Setting.Elements[i].FolderPath;
                AssetBundleCollectorSetting.EFolderPackRule  packRule  = AssetBundleCollectorSettingData.Setting.Elements[i].PackRule;
                AssetBundleCollectorSetting.EBundleLabelRule labelRule = AssetBundleCollectorSettingData.Setting.Elements[i].LabelRule;

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(folderPath);

                    AssetBundleCollectorSetting.EFolderPackRule newPackRule = (AssetBundleCollectorSetting.EFolderPackRule)EditorGUILayout.EnumPopup(packRule, GUILayout.MaxWidth(150));
                    if (newPackRule != packRule)
                    {
                        packRule = newPackRule;
                        AssetBundleCollectorSettingData.ModifyElement(folderPath, packRule, labelRule);
                    }

                    AssetBundleCollectorSetting.EBundleLabelRule newLabelRule = (AssetBundleCollectorSetting.EBundleLabelRule)EditorGUILayout.EnumPopup(labelRule, GUILayout.MaxWidth(150));
                    if (newLabelRule != labelRule)
                    {
                        labelRule = newLabelRule;
                        AssetBundleCollectorSettingData.ModifyElement(folderPath, packRule, labelRule);
                    }

                    if (GUILayout.Button("-", GUILayout.MaxWidth(40)))
                    {
                        AssetBundleCollectorSettingData.RemoveElement(folderPath);
                        break;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            // 添加按钮
            if (GUILayout.Button("+"))
            {
                string resultPath = EditorTools.OpenFolderPanel("+", _lastOpenFolderPath);
                if (resultPath != null)
                {
                    _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath);
                    AssetBundleCollectorSettingData.AddElement(_lastOpenFolderPath);
                }
            }
        }
示例#2
0
        /// <summary>
        /// 编辑元素
        /// </summary>
        public static void ModifyElement(string folderPath, AssetBundleCollectorSetting.EFolderPackRule packRule, AssetBundleCollectorSetting.EBundleLabelRule labelRule)
        {
            // 注意:这里强制修改忽略文件夹的命名规则为None
            if (packRule == AssetBundleCollectorSetting.EFolderPackRule.Ignore)
            {
                labelRule = AssetBundleCollectorSetting.EBundleLabelRule.None;
            }
            else
            {
                if (labelRule == AssetBundleCollectorSetting.EBundleLabelRule.None)
                {
                    labelRule = AssetBundleCollectorSetting.EBundleLabelRule.LabelByFilePath;
                }
            }

            for (int i = 0; i < Setting.Elements.Count; i++)
            {
                if (Setting.Elements[i].FolderPath == folderPath)
                {
                    Setting.Elements[i].PackRule  = packRule;
                    Setting.Elements[i].LabelRule = labelRule;
                    break;
                }
            }
            SaveFile();
        }