Пример #1
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;
        }
Пример #2
0
 protected void DrawArrayTitle(Rect pos, SerializedProperty prop, GUIContent label, float xOffset)
 {
     label.text += " [" + prop.arraySize + "]";
     pos.x       = xOffset;
     GUITools.Label(pos, label, GUITools.black, GUITools.boldLabel);
 }