private void DrawCustoms() { serializedSettings.UpdateIfRequiredOrScript(); var customTypes = serializedSettings.FindProperty("customTypes"); if (customTypes.arraySize == 0) { if (GUILayout.Button("Add", EditorStyles.miniButtonRight)) { customTypes.InsertArrayElementAtIndex(0); serializedSettings.ApplyModifiedProperties(); } } string[] customNames = new string[customTypes.arraySize]; EditorGUI.indentLevel++; SerializedProperty customType = null; SerializedProperty script = null; Object scriptValue = null; for (int i = 0; i < customTypes.arraySize; i++) { customType = customTypes.GetArrayElementAtIndex(i); script = customType.FindPropertyRelative("script"); scriptValue = script.objectReferenceValue; string displayName = scriptValue == null ? "Empty Custom Element" : scriptValue.name; //Draw header for the custom type EditorGUILayout.BeginHorizontal(); { GUIHelper.GetSerializedFoldout(customType, displayName); if (GUILayout.Button("Delete", EditorStyles.miniButtonLeft)) { settings.customTypes.RemoveAt(i); } else if (GUILayout.Button("Add", EditorStyles.miniButtonRight)) { settings.customTypes.Insert(i + 1, null); } } EditorGUILayout.EndHorizontal(); //Drwa all children afterwards if (customType.isExpanded) { EditorGUI.BeginChangeCheck(); { SerializedPropertyUtility.DrawChildrenProperties(customType, false); } if (EditorGUI.EndChangeCheck()) { serializedSettings.ApplyModifiedProperties(); settings.customTypes[i].UpdateScriptType(); } } } EditorGUI.indentLevel--; }
private void DrawStyleElements(Rect rect, int index, bool isActive, bool isFocused) { rect.x += 3f; rect.width -= 3f; if (index >= serializedStyles.arraySize) { return; } SerializedProperty style = serializedStyles.GetArrayElementAtIndex(index); SerializedProperty nameProp = style.FindPropertyRelative("name"); Rect removeRect = rect; removeRect.x = removeRect.width + 6f; removeRect.width = 48f; removeRect.height = 18f; if (GUI.Button(removeRect, "Delete", EditorStyles.centeredGreyMiniLabel)) { serializedStyles.DeleteArrayElementAtIndex(index); serializedSettings.ApplyModifiedProperties(); serializedSettings.Update(); return; } rect.y--; Rect foldoutRect = GetFoldoutRect(rect); Rect labelRect = GetStyleLabelRect(rect); Rect styleRect = GetStyleRect(rect); EditorGUI.BeginChangeCheck(); { HierarchyGUI.DrawHierarchyStyle(settings.styleData[index], styleRect, labelRect, nameProp.stringValue, false); // Use GUI over EditorGUI due to overlapping on draggable style.isExpanded = GUI.Toggle(foldoutRect, style.isExpanded, "", EditorStyles.foldout); Rect propertyRect = GetStylePropertyRect(rect); if (style.isExpanded) { Rect box = propertyRect; box.height -= 18f; box.x = styleRect.x; box.width = styleRect.width; box.y -= 3f; GUI.Box(box, ""); var customDraws = new Dictionary <string, Action <Rect, SerializedProperty> > () { { "modes", DrawModes } }; SerializedPropertyUtility.DrawChildrenProperties(propertyRect, style, style.isExpanded, customDraws); } } if (EditorGUI.EndChangeCheck()) { serializedSettings.ApplyModifiedProperties(); serializedSettings.Update(); settings.styleData[index].UpdateStyle(EditorGUIUtility.isProSkin); } }