private void PropertyGroupPanel(ImporterGroup importerGroup, PropertyGroup propertyGroup)
 {
     propertyGroup.SerializedObject.Update();
     using (new GUILayout.VerticalScope("CN Box", GUILayout.MaxWidth(100000)))
     {
         //头部
         using (new GUILayout.HorizontalScope())
         {
             GUILayout.Label(propertyGroup.Name, "BoldLabel");
             GUILayout.FlexibleSpace();
             //选择字段
             if (GUILayout.Button("Choose Properties", GUILayout.MaxWidth(120)))
             {
                 ShowChoosePropertiesMenu(importerGroup, propertyGroup);
             }
         }
         EditorGUILayout.Separator();
         //显示字段
         foreach (var fieldName in importerGroup.FieldNames)
         {
             if (propertyGroup.Properties.Exists(x => x.Name == fieldName))
             {
                 EditorGUILayout.PropertyField(propertyGroup.SerializedObject.FindProperty(fieldName), true);
             }
         }
         //应用修改
         if (propertyGroup.SerializedObject.ApplyModifiedProperties())
         {
             G.Module.IsDirty = true;
         }
     }
 }
Exemple #2
0
        public void InitImporterGroups()
        {
            Type baseType = typeof(ImporterSetting);

            foreach (Type type in baseType.Assembly.GetTypes())
            {
                if (type.IsSubclassOf(baseType))
                {
                    Type   settingType   = type;
                    var    attribute     = (SetForAttribute)settingType.GetCustomAttributes(typeof(SetForAttribute), true)[0];
                    Type   targetType    = attribute.TargetType;
                    string targetName    = targetType.Name;
                    var    importerGroup = Json.ImporterGroups.Find(x => x.Name == targetName);
                    if (importerGroup == null)
                    {
                        importerGroup      = new ImporterGroup();
                        importerGroup.Name = targetName;
                        Json.ImporterGroups.Add(importerGroup);
                    }
                    importerGroup.SettingType  = settingType;
                    importerGroup.TargetType   = targetType;
                    importerGroup.Fields       = settingType.GetFields(BindingFlags.Instance | BindingFlags.Public);
                    importerGroup.FieldNames   = importerGroup.Fields.Select(x => x.Name).ToArray();
                    importerGroup.SearchFilter = attribute.SearchFilter;
                }
            }
            ;
        }
 private bool LabelGroupPanel(ImporterGroup importerGroup, LabelGroup labelGroup)
 {
     using (new GUILayout.VerticalScope("GroupBox"))
     {
         //头部
         using (new GUILayout.HorizontalScope())
         {
             labelGroup.Active          = EditorGUILayout.ToggleLeft(GUIContent.none, labelGroup.Active, GUILayout.Width(20));
             labelGroup.LabelExpression = EditorGUILayout.TextField(labelGroup.LabelExpression);
             if (GUILayout.Button("×", GUILayout.Width(20))) //删除LabelGroup
             {
                 RemoveLabelGroup(importerGroup, labelGroup);
                 return(true);
             }
         }
         using (new EditorGUI.DisabledGroupScope(!labelGroup.Active))
         {
             //每一个属性
             using (new GUILayout.HorizontalScope())
             {
                 foreach (var propertyGroup in labelGroup.PropertyGroups)
                 {
                     PropertyGroupPanel(importerGroup, propertyGroup);
                 }
             }
         }
     }
     return(false);
 }
        private void ShowChoosePropertiesMenu(ImporterGroup importerGroup, PropertyGroup propertyGroup)
        {
            GenericMenu menu = new GenericMenu();

            foreach (string fieldName in importerGroup.FieldNames)
            {
                Property property = propertyGroup.Properties.Find(x => x.Name == fieldName);
                bool     exist    = property != null;
                menu.AddItem(new GUIContent(fieldName), exist, () =>
                {
                    if (!exist)
                    {
                        propertyGroup.Properties.Add(new Property()
                        {
                            Name = fieldName
                        });
                    }
                    else
                    {
                        propertyGroup.Properties.Remove(property);
                    }
                    G.Module.IsDirty = true;
                });
            }
            menu.ShowAsContext();
        }
 private void RemoveLabelGroup(ImporterGroup importerGroup, LabelGroup labelGroup)
 {
     if (labelGroup.PropertyGroups.All(x => x.Properties.Count == 0) || G.Module.DisplayDialog("确定删除该组?\n\n" + labelGroup.LabelExpression, "确定", "取消"))
     {
         importerGroup.LabelGroups.Remove(labelGroup);
         G.Module.IsDirty = true;
         EditorGUIUtility.editingTextField = false;
     }
 }
        private void AddLabelGroup(ImporterGroup importerGroup)
        {
            var labelGroup = new LabelGroup();

            foreach (var propertyGroup in labelGroup.PropertyGroups)
            {
                propertyGroup.ImporterSetting  = (ImporterSetting)ScriptableObject.CreateInstance(importerGroup.SettingType);
                propertyGroup.SerializedObject = new SerializedObject(propertyGroup.ImporterSetting);
            }
            importerGroup.LabelGroups.Add(labelGroup);
            G.Module.IsDirty = true;
            EditorGUIUtility.editingTextField = false;
        }
 private void ImporterGroupPanel(ImporterGroup importerGroup)
 {
     using (new GUILayout.VerticalScope(GUILayout.MaxWidth(100000)))
     {
         //头部
         using (new GUILayout.HorizontalScope())
         {
             if (GUILayout.Button("+", GUILayout.Width(20)))
             {
                 AddLabelGroup(importerGroup);
             }
             GUILayout.Label(importerGroup.Name, "BoldLabel");
         }
         //每一个LabelGroup
         foreach (var labelGroup in importerGroup.LabelGroups)
         {
             if (LabelGroupPanel(importerGroup, labelGroup))//返回true表示发生了删除操作
             {
                 break;
             }
         }
         GUILayout.FlexibleSpace();
     }
 }