Пример #1
0
        /*
         *  TODO:
         *      MOVE BUTTONS:
         *
         * if (GUILayout.Button("↑↑", UnityBuildGUIUtility.helpButtonStyle))
         * {
         * list.MoveArrayElement(i, 0);
         * }
         * if (GUILayout.Button("↑", UnityBuildGUIUtility.helpButtonStyle))
         * {
         * list.MoveArrayElement(i, i - 1);
         * }
         * if (GUILayout.Button("↓", UnityBuildGUIUtility.helpButtonStyle))
         * {
         * list.MoveArrayElement(i, i + 1);
         * }
         *
         */

        protected float CalculateHeight(SerializedProperty prop, bool displayed)
        {
            if (!displayed)
            {
                return(GUITools.singleLineHeight);
            }

            NeatArrayAttribute att     = attribute as NeatArrayAttribute;
            string             tooltip = att != null ? att.tooltip : string.Empty;

            float h         = GUITools.singleLineHeight * (string.IsNullOrEmpty(tooltip) ? 1 : 2);
            int   arraySize = prop.arraySize;

            for (int i = 0; i < arraySize; i++)
            {
                h += EditorGUI.GetPropertyHeight(prop.GetArrayElementAtIndex(i), true);
            }
            return(h);
        }
Пример #2
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            NeatArrayAttribute att = attribute as NeatArrayAttribute;
            int origIndentLevel    = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            float indent1, indent2, indent2Width;
            bool  displayedValue;


            string lbl = label.text;

            StartArrayDraw(pos, ref prop, out indent1, out indent2, out indent2Width, out displayedValue);

            if (att != null)
            {
                MakeSureSizeIsOK(prop, att.enforceSize);
            }
            if (att == null || att.enforceSize < 0)
            {
                DrawAddElement(pos, prop, indent1, displayedValue);
            }

            float xOffset = (att == null || att.enforceSize < 0 ? indent2 : indent1) + GUITools.toolbarDividerSize;

            // DrawArrayTitle ( pos, prop.arraySize, lbl, att != null ? att.tooltip : string.Empty, xOffset );

            string tooltip = att != null ? att.tooltip : string.Empty;

            lbl += " [" + prop.arraySize + "] ";
            GUITools.Label(new Rect(xOffset, pos.y, pos.width, pos.height), new GUIContent(lbl), GUITools.black, GUITools.boldLabel);

            bool showsTooltip = false;

            if (displayedValue && !string.IsNullOrEmpty(tooltip))
            {
                showsTooltip = true;
                GUIContent ttGUI = new GUIContent(tooltip);
                // float ttWidth = tooltipStyle.CalcSize(ttGUI).x;
                // GUITools.Label(new Rect(pos.x + pos.width - ttWidth, pos.y, ttWidth, pos.height), ttGUI, GUITools.black, tooltipStyle);
                GUITools.Label(new Rect(xOffset, pos.y + EditorGUIUtility.singleLineHeight, pos.width, pos.height), ttGUI, GUITools.black, tooltipStyle);
            }



            if (displayedValue)
            {
                int indexToDelete = -1;

                pos.x      = xOffset;
                pos.y     += GUITools.singleLineHeight * (showsTooltip ? 2 : 1);
                pos.width  = indent2Width - GUITools.toolbarDividerSize * 2;
                pos.height = EditorGUIUtility.singleLineHeight;

                GUIContent deleteContent = BuiltInIcons.GetIcon("Toolbar Minus", "Delete Element");
                for (int i = 0; i < prop.arraySize; i++)
                {
                    if (att == null || att.enforceSize < 0)
                    {
                        if (GUITools.IconButton(indent1, pos.y, deleteContent, GUITools.red))
                        {
                            indexToDelete = i;
                        }
                    }

                    SerializedProperty p = prop.GetArrayElementAtIndex(i);
                    EditorGUI.PropertyField(pos, p, GUITools.noContent, true);

                    pos.y += EditorGUI.GetPropertyHeight(p, true);
                }

                if (indexToDelete != -1)
                {
                    SerializedProperty p = prop.GetArrayElementAtIndex(indexToDelete);

                    if (p.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        if ((prop.objectReferenceValue) != null)
                        {
                            prop.DeleteArrayElementAtIndex(indexToDelete);
                        }
                    }
                    prop.DeleteArrayElementAtIndex(indexToDelete);
                }
            }
            EditorGUI.indentLevel = origIndentLevel;
        }
Пример #3
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            NeatArrayAttribute att = attribute as NeatArrayAttribute;

            float indent1, indent2, indent2Width;
            bool  displayedValue;

            StartArrayDraw(pos, ref prop, ref label, out indent1, out indent2, out indent2Width, out displayedValue);

            if (att != null)
            {
                MakeSureSizeIsOK(prop, att.enforceSize);
            }

            if (att == null || att.enforceSize < 0)
            {
                DrawAddElement(pos, prop, indent1, displayedValue);
            }

            float xOffset = (att == null || att.enforceSize < 0 ? indent2 : indent1) + GUITools.toolbarDividerSize;

            DrawArrayTitle(pos, prop, label, xOffset);

            if (displayedValue)
            {
                int indexToDelete = -1;

                pos.x      = xOffset;
                pos.y     += GUITools.singleLineHeight;
                pos.width  = indent2Width - GUITools.toolbarDividerSize * 2;
                pos.height = EditorGUIUtility.singleLineHeight;

                for (int i = 0; i < prop.arraySize; i++)
                {
                    if (att == null || att.enforceSize < 0)
                    {
                        if (GUITools.IconButton(indent1, pos.y, deleteContent, GUITools.red))
                        {
                            indexToDelete = i;
                        }
                    }

                    SerializedProperty p = prop.GetArrayElementAtIndex(i);
                    EditorGUI.PropertyField(pos, p, true);

                    pos.y += EditorGUI.GetPropertyHeight(p, true);
                }

                if (indexToDelete != -1)
                {
                    SerializedProperty p = prop.GetArrayElementAtIndex(indexToDelete);

                    OnDeleteElement(p);

                    if (p.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        prop.DeleteArrayElementAtIndex(indexToDelete);
                    }
                    prop.DeleteArrayElementAtIndex(indexToDelete);
                }
            }

            EditorGUI.EndProperty();
        }