public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool cache = property.isExpanded;

            property.isExpanded = true;

            if (!property.hasChildren)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            float h        = SPEditorGUI.GetDefaultPropertyHeight(property, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight;
            var   area     = new Rect(position.x, position.yMax - h, position.width, h);
            var   drawArea = new Rect(area.x, area.y + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD);

            GUI.BeginGroup(area, label, GUI.skin.box);
            GUI.EndGroup();

            EditorGUI.indentLevel++;
            SPEditorGUI.FlatChildPropertyField(drawArea, property);
            EditorGUI.indentLevel--;

            property.isExpanded = cache;
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool canShrink = this.attribute is DisplayFlatAttribute ? (this.attribute as DisplayFlatAttribute).CanShrinkAndExpand : false;

            bool cache = property.isExpanded;

            if (!canShrink)
            {
                property.isExpanded = true;
            }
            try
            {
                if (!property.hasChildren)
                {
                    SPEditorGUI.DefaultPropertyField(position, property, label);
                    return;
                }

                if (canShrink)
                {
                    cache = SPEditorGUI.PrefixFoldoutLabel(position, property.isExpanded, GUIContent.none);
                }

                if (property.isExpanded)
                {
                    float h        = SPEditorGUI.GetDefaultPropertyHeight(property, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight;
                    var   area     = new Rect(position.x, position.yMax - h, position.width, h);
                    var   drawArea = new Rect(area.x, area.y + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD);

                    GUI.BeginGroup(area, label, GUI.skin.box);
                    GUI.EndGroup();

                    EditorGUI.indentLevel++;
                    SPEditorGUI.FlatChildPropertyField(drawArea, property);
                    EditorGUI.indentLevel--;
                }
                else
                {
                    GUI.BeginGroup(position, label, GUI.skin.box);
                    GUI.EndGroup();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                property.isExpanded = cache;
            }
        }
        private void DrawSettings(Rect position, SerializedProperty property)
        {
            var r3a = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            var propApplySettings = property.FindPropertyRelative(PROP_APPPLYSETTINGS);

            SPEditorGUI.PropertyField(r3a, propApplySettings);
            if (propApplySettings.boolValue)
            {
                var r3b = new Rect(position.xMin, r3a.yMax, position.width, position.height - EditorGUIUtility.singleLineHeight);
                EditorGUI.indentLevel++;
                SPEditorGUI.FlatChildPropertyField(r3b, property.FindPropertyRelative(PROP_SETTINGS));
                EditorGUI.indentLevel--;
            }
        }
        protected virtual void DrawElement(Rect area, SerializedProperty element, GUIContent label, int elementIndex)
        {
            if (_drawElementAtBottom)
            {
                SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry);

                if (prop != null)
                {
                    SPEditorGUI.PropertyField(area, prop, label);
                }
                else
                {
                    EditorGUI.LabelField(area, label);
                }
            }
            else
            {
                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(area, element, label);
                }
                else if (ElementIsFlatChildField(element))
                {
                    //we don't draw this way if it's a built-in type from Unity

                    if (_hideElementLabel)
                    {
                        //no label
                        SPEditorGUI.FlatChildPropertyField(area, element);
                    }
                    else
                    {
                        //showing label
                        var labelArea = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
                        EditorGUI.LabelField(labelArea, label);
                        var childArea = new Rect(area.xMin, area.yMin + EditorGUIUtility.singleLineHeight + 1f, area.width, area.height - EditorGUIUtility.singleLineHeight);
                        SPEditorGUI.FlatChildPropertyField(childArea, element);
                    }
                }
                else
                {
                    area = EditorGUI.PrefixLabel(area, label);
                    SPEditorGUI.DefaultPropertyField(area, element, label, false);
                }
            }
        }
Exemplo n.º 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            if (property.isArray)
            {
                if (this.CustomLabel != null)
                {
                    label = this.CustomLabel;
                }
                else if (label != null)
                {
                    label = EditorHelper.CloneContent(label);
                    if (_showTooltipInHeader)
                    {
                        label.text = string.Format("{0} [{1:0}] - {2}", label.text, property.arraySize, (string.IsNullOrEmpty(label.tooltip) ? property.tooltip : label.tooltip));
                    }
                    else
                    {
                        label.text = string.Format("{0} [{1:0}]", label.text, property.arraySize);
                    }

                    if (string.IsNullOrEmpty(label.tooltip))
                    {
                        label.tooltip = property.tooltip;
                    }
                }
                else
                {
                    label = EditorHelper.TempContent(property.displayName, property.tooltip);
                }

                //const float WIDTH_FOLDOUT = 5f;
                var foldoutRect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                position = EditorGUI.IndentedRect(position);
                Rect listArea = position;

                if (_disallowFoldout)
                {
                    listArea = new Rect(position.xMin, position.yMin, position.width, _lst.GetHeight());
                    this.StartOnGUI(property, label);
                    //_lst.DoList(EditorGUI.IndentedRect(position));
                    _lst.DoList(listArea);
                    this.EndOnGUI(property, label);
                }
                else
                {
                    if (property.isExpanded)
                    {
                        listArea = new Rect(position.xMin, position.yMin, position.width, _lst.GetHeight());
                        this.StartOnGUI(property, label);
                        property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none);
                        //_lst.DoList(EditorGUI.IndentedRect(position));
                        _lst.DoList(listArea);
                        this.EndOnGUI(property, label);
                    }
                    else
                    {
                        if (_removeBackgroundWhenCollapsed)
                        {
                            property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label);
                        }
                        else
                        {
                            property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none);
                            //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label);
                            ReorderableListHelper.DrawRetractedHeader(position, label);
                        }
                    }
                }

                this.DoDragAndDrop(property, listArea);

                if (property.isExpanded && _drawElementAtBottom && _lst.index >= 0 && _lst.index < property.arraySize)
                {
                    var pchild = property.GetArrayElementAtIndex(_lst.index);
                    var label2 = TempElementLabel(pchild, _lst.index); //(string.IsNullOrEmpty(_childPropertyAsLabel)) ? TempElementLabel(_lst.index) : GUIContent.none;

                    pchild.isExpanded = true;
                    float h;
                    if (_internalDrawer != null)
                    {
                        h = _internalDrawer.GetPropertyHeight(pchild, label2) + BOTTOM_PAD + TOP_PAD;
                    }
                    else if (pchild.hasChildren)
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight;
                    }
                    else
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD + TOP_PAD;
                    }
                    var area     = new Rect(position.xMin, position.yMax - h, position.width, h);
                    var drawArea = new Rect(area.xMin, area.yMin + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD);

                    GUI.BeginGroup(area, label2, GUI.skin.box);
                    GUI.EndGroup();

                    EditorGUI.indentLevel++;
                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(drawArea, pchild, label2);
                    }
                    else if (pchild.hasChildren)
                    {
                        SPEditorGUI.FlatChildPropertyField(drawArea, pchild);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(drawArea, pchild, GUIContent.none, false);
                    }
                    EditorGUI.indentLevel--;
                }
            }
            else
            {
                SPEditorGUI.DefaultPropertyField(position, property, label, false);
            }
        }
Exemplo n.º 6
0
        private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            //EditorGUI.PropertyField(area, element, GUIContent.none, false);
            var        attrib = this.attribute as ReorderableArrayAttribute;
            GUIContent label  = GUIContent.none;

            if (attrib != null)
            {
                if (attrib.ElementLabelFormatString != null)
                {
                    label = EditorHelper.TempContent(string.Format(attrib.ElementLabelFormatString, index));
                }
                if (attrib.ElementPadding > 0f)
                {
                    area = new Rect(area.xMin + attrib.ElementPadding, area.yMin, Mathf.Max(0f, area.width - attrib.ElementPadding), area.height);
                }
            }

            if (_drawElementAtBottom)
            {
                var lbl = TempElementLabel(element, index);
                SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry);

                if (prop != null)
                {
                    SPEditorGUI.PropertyField(area, prop, lbl);
                }
                else
                {
                    EditorGUI.LabelField(area, lbl);
                }
            }
            else
            {
                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(area, element, label);
                }
                else if (element.hasChildren && element.objectReferenceValue is MonoBehaviour)
                {
                    //we don't draw this way if it's a built-in type from Unity
                    var labelArea = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
                    EditorGUI.LabelField(labelArea, label);
                    var childArea = new Rect(area.xMin, area.yMin + EditorGUIUtility.singleLineHeight + 1f, area.width, area.height - EditorGUIUtility.singleLineHeight);
                    SPEditorGUI.FlatChildPropertyField(childArea, element);
                }
                else
                {
                    SPEditorGUI.DefaultPropertyField(area, element, label, false);
                }
            }

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }