Example #1
0
        public static void AddArray(SerializedContent content, bool editHierarchy, bool changeOrder, DrawArrayElement drawArrayElement = null, OnAddToArray onAddToArray = null, DrawArrayElementLabel drawArrayElementLabel = null, bool showHeading = true)
        {
            int resetIndent = EditorGUI.indentLevel;

            // Array heading
            if (showHeading) {
                GUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * indent);

                if (drawArrayElement == null) {
                    GUILayout.Label(content.guiContent.text + " (" + content.prop.arraySize.ToString() + ")", GUILayout.Width(150));
                } else {
                    EditorGUILayout.PropertyField(content.prop, new GUIContent(content.guiContent.text + " (" + content.prop.arraySize.ToString() + ")", string.Empty), false, GUILayout.Width(150));
                }

                GUILayout.EndHorizontal();
            }

            int deleteIndex = -1;

            if (drawArrayElement == null || !showHeading) content.prop.isExpanded = true;

            // Draw Array elements
            if (content.prop.isExpanded) {
                for(int i = 0; i < content.prop.arraySize; i++) {
                    GUILayout.BeginHorizontal(); // Main
                    GUILayout.Space(((EditorGUI.indentLevel + 1) * indent));
                    GUILayout.BeginVertical();

                    element = content.prop.GetArrayElementAtIndex(i);

                    // Label
                    GUILayout.BeginHorizontal();

                    if (editHierarchy && GUILayout.Button(new GUIContent("-", "Remove"), changeOrder? EditorStyles.miniButtonLeft: EditorStyles.miniButton, GUILayout.Width(20))){
                        deleteIndex = i;
                    }

                    if (changeOrder) {
                        if (GUILayout.Button(new GUIContent("<", "Move up"), editHierarchy? EditorStyles.miniButtonMid: EditorStyles.miniButtonLeft, GUILayout.Width(20))) {
                            int moveTo = i == 0? content.prop.arraySize - 1: i - 1;
                            content.prop.MoveArrayElement(i, moveTo);
                            content.prop.isExpanded = true;
                        }

                        if (GUILayout.Button(new GUIContent(">", "Move down"), EditorStyles.miniButtonRight, GUILayout.Width(20))) {
                            int moveTo = i == content.prop.arraySize - 1? 0: i + 1;
                            content.prop.MoveArrayElement(i, moveTo);
                            content.prop.isExpanded = true;
                        }
                    }

                    // Calling the DrawArrayElementLabel delegate
                    if (drawArrayElementLabel != null) {
                        drawArrayElementLabel(element, editHierarchy);
                    }

                    GUILayout.EndHorizontal(); // End Label

                    // Array Element
                    GUILayout.BeginVertical();
                    if (element.isExpanded && drawArrayElement != null) {
                        drawArrayElement(element, editHierarchy);
                    }
                    GUILayout.EndVertical();

                    GUILayout.Space(5);

                    GUILayout.EndVertical(); // End Style
                    GUILayout.EndHorizontal(); // End Main
                }

                // Deleting array elements
                if (deleteIndex != -1) content.prop.DeleteArrayElementAtIndex(deleteIndex);

                // Adding array elements
                GUILayout.BeginHorizontal();
                GUILayout.Space(((EditorGUI.indentLevel + 1) * indent) + 4);
                GUILayout.BeginVertical();

                if (editHierarchy && GUILayout.Button(new GUIContent("+", "Add"), EditorStyles.miniButton, GUILayout.Width(20))) {
                    content.prop.arraySize ++;

                    if (onAddToArray != null) onAddToArray(content.prop.GetArrayElementAtIndex(content.prop.arraySize - 1));
                }

                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel = resetIndent;
        }
Example #2
0
 public static void AddContent(SerializedContent content, bool addChildren = false, params GUILayoutOption[] options)
 {
     EditorGUILayout.PropertyField(content.prop, content.guiContent, addChildren, options);
 }
Example #3
0
 public static void AddClampedFloat(SerializedContent content, float min = 0f, float max = 1f, params GUILayoutOption[] options)
 {
     AddClampedFloat(content.prop, content.guiContent, min, max, options);
 }
Example #4
0
 public static void AddClampedInt(SerializedContent content, int min = int.MinValue, int max = int.MaxValue, params GUILayoutOption[] options)
 {
     AddClampedInt(content.prop, content.guiContent, min, max, options);
 }
Example #5
0
 public static void AddContent(SerializedContent content, bool addChildren = false, params GUILayoutOption[] options)
 {
     EditorGUILayout.PropertyField(content.prop, content.guiContent, addChildren, options);
 }