public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!_toShow)
            {
                return;
            }

            if (_multipleAttributes && _genericDrawerInstance != null)
            {
                try
                {
                    _genericDrawerInstance.OnGUI(position, property, label);
                }
                catch (Exception e)
                {
                    EditorGUI.PropertyField(position, property, label);
                    LogWarning("Unable to instantiate " + _genericAttribute.GetType() + " : " + e, property);
                }
            }
            else if (_specialType && _genericTypeDrawerInstance != null)
            {
                try
                {
                    _genericTypeDrawerInstance.OnGUI(position, property, label);
                }
                catch (Exception e)
                {
                    EditorGUI.PropertyField(position, property, label);
                    LogWarning("Unable to instantiate " + _genericType + " : " + e, property);
                }
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
        }
Ejemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            if (property.isArray)
            {
                if (_disallowFoldout)
                {
                    this.StartOnGUI(property, label);
                    //_lst.DoList(EditorGUI.IndentedRect(position));
                    _lst.DoList(position);
                    this.EndOnGUI(property, label);
                }
                else
                {
                    const float WIDTH_FOLDOUT = 5f;
                    if (property.isExpanded)
                    {
                        this.StartOnGUI(property, label);
                        property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
                        //_lst.DoList(EditorGUI.IndentedRect(position));
                        _lst.DoList(position);
                        this.EndOnGUI(property, label);
                    }
                    else
                    {
                        if (_removeBackgroundWhenCollapsed)
                        {
                            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
                        }
                        else
                        {
                            property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
                            //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label);
                            ReorderableListHelper.DrawRetractedHeader(position, label);
                        }
                    }
                }

                if (_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;
                    }
                    else
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD;
                    }
                    var area = new Rect(position.x, position.yMax - h, position.width, h);

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

                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(area, pchild, label2);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(area, pchild, GUIContent.none, true);
                    }
                }
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, false);
            }
        }
Ejemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!property.isArray)
            {
                EditorGUI.PropertyField(position, property, label, false);
                return;
            }

            if (property.arraySize == 0)
            {
                property.arraySize = 1;
            }

            if (property.arraySize == 1)
            {
                var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(0), label) : EditorGUIUtility.singleLineHeight;
                var propArea      = new Rect(position.xMin, position.yMin, Mathf.Max(0f, position.width - BTN_WIDTH), elementHeight);
                var btnArea       = new Rect(propArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight);

                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(propArea, property.GetArrayElementAtIndex(0), label);
                }
                else
                {
                    SPEditorGUI.DefaultPropertyField(propArea, property.GetArrayElementAtIndex(0), label);
                }
                if (GUI.Button(btnArea, _moreBtnLabel))
                {
                    property.arraySize = 2;
                }
            }
            else
            {
                var elementArea = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

                //draw header
                var leftOverArea = EditorGUI.PrefixLabel(elementArea, label ?? GUIContent.none);
                var sizeArea     = new Rect(Mathf.Max(leftOverArea.xMin, leftOverArea.xMax - BTN_WIDTH - SIZE_WIDTH),
                                            leftOverArea.yMin,
                                            Mathf.Min(SIZE_WIDTH, Mathf.Max(0f, leftOverArea.width - BTN_WIDTH)), EditorGUIUtility.singleLineHeight);
                var btnArea = new Rect(sizeArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight);
                property.arraySize = Mathf.Max(EditorGUI.IntField(sizeArea, property.arraySize), 1);
                if (GUI.Button(btnArea, _oneBtnLabel))
                {
                    property.arraySize = 1;
                }

                EditorGUI.indentLevel++;
                for (int i = 0; i < property.arraySize; i++)
                {
                    var lbl           = EditorHelper.TempContent("Element " + i.ToString());
                    var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(i), lbl) : EditorGUIUtility.singleLineHeight;
                    elementArea = new Rect(position.xMin, elementArea.yMax, position.width, elementHeight);

                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(elementArea, property.GetArrayElementAtIndex(i), lbl);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(elementArea, property.GetArrayElementAtIndex(i), lbl);
                    }
                }
                EditorGUI.indentLevel--;
            }
        }
Ejemplo n.º 4
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);
            }
        }
        /// <inheritdoc />
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Retrieve attributes
            List <ConditionalAttribute> conditionalAttributes = new List <ConditionalAttribute>();

            // ColorUsageAttribute colorUsageAttribute = null;
#if UNITY_5_3_OR_NEWER
            DelayedAttribute delayedAttribute = null;
#endif
            MultilineAttribute multilineAttribute = null;
            TextAreaAttribute  textAreaAttribute  = null;
            RangeAttribute     rangeAttribute     = null;
            ReadOnlyAttribute  readOnlyAttribute  = null;

            object[] customAttributes = fieldInfo.GetCustomAttributes(false);
            for (int i = 0; i < customAttributes.Length; i++)
            {
                if (customAttributes[i] is ConditionalAttribute)
                {
                    conditionalAttributes.Add((ConditionalAttribute)customAttributes[i]);
                }
                // else if (customAttributes[i] is ColorUsageAttribute)
                // {
                //     colorUsageAttribute = (ColorUsageAttribute)customAttributes[i];
                // }
#if UNITY_5_3_OR_NEWER
                else if (customAttributes[i] is DelayedAttribute)
                {
                    delayedAttribute = (DelayedAttribute)customAttributes[i];
                }
#endif
                else if (customAttributes[i] is MultilineAttribute)
                {
                    multilineAttribute = (MultilineAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is TextAreaAttribute)
                {
                    textAreaAttribute = (TextAreaAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is RangeAttribute)
                {
                    rangeAttribute = (RangeAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is ReadOnlyAttribute)
                {
                    readOnlyAttribute = (ReadOnlyAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is TooltipAttribute ||
                         customAttributes[i] is SerializeField ||
                         customAttributes[i] is NonSerializedAttribute)
                {
                    // Ignored attributes
                }
                else
                {
                    Debug.LogWarning("ConditionalPropertyDrawer needs implementation for type " + customAttributes[i].ToString());
                }
            }

            int conditionCount = 0;
            for (int i = 0; i < conditionalAttributes.Count; i++)
            {
                if (conditionalAttributes[i].Conditions != null)
                {
                    conditionCount += conditionalAttributes[i].Conditions.Length;
                }
            }

            ConditionalAttribute.Condition[] conditions = new ConditionalAttribute.Condition[conditionCount];

            int index = 0;
            for (int i = 0; i < conditionalAttributes.Count; i++)
            {
                if (conditionalAttributes[i].Conditions != null)
                {
                    ConditionalAttribute.Condition[] conds = conditionalAttributes[i].Conditions;
                    for (int j = 0; j < conds.Length; j++)
                    {
                        conditions[index++] = conds[j];
                    }
                }
            }

            Attribute.Show = true;
            try
            {
                Attribute.Show = ShouldShow(property, conditions);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            if (Attribute.Show)
            {
                if (readOnlyAttribute != null)
                {
                    GUI.enabled = false;
                }

                // Implementations obtained through inspection
#if UNITY_5_3_OR_NEWER
                if (delayedAttribute != null)
                {
                    PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.DelayedDrawer,UnityEditor");
                    propertyDrawer.OnGUI(position, property, label);
                }
                else
#endif

/*                 if (colorUsageAttribute != null)
 *              {
 *
 *                  EditorGUI.BeginChangeCheck();
 #if UNITY_5_3_OR_NEWER
 *                  ColorPickerHDRConfig hdrConfig = new ColorPickerHDRConfig(
 *                      colorUsageAttribute.minBrightness, colorUsageAttribute.maxBrightness,
 *                      colorUsageAttribute.minExposureValue, colorUsageAttribute.maxExposureValue);
 *                  Color color = EditorGUI.ColorField(position, label, property.colorValue,
 *                      true, colorUsageAttribute.showAlpha, colorUsageAttribute.hdr, hdrConfig);
 #else
 *                                      Color color = EditorGUI.ColorField(position, label, property.colorValue);
 #endif
 *                  if (EditorGUI.EndChangeCheck())
 *                  {
 *                      property.colorValue = color;
 *                  }
 *              }
 *              else
 */
                if (multilineAttribute != null)
                {
                    PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.MultilineDrawer,UnityEditor");
                    propertyDrawer.OnGUI(position, property, label);
                }
                else if (textAreaAttribute != null)
                {
                    PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.TextAreaDrawer,UnityEditor");
                    propertyDrawer.OnGUI(position, property, label);
                }
                else if (rangeAttribute != null)
                {
                    if (property.propertyType == SerializedPropertyType.Float)
                    {
                        EditorGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label);
                    }
                    else if (property.propertyType == SerializedPropertyType.Integer)
                    {
                        EditorGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label);
                    }
                    else
                    {
                        EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
                    }
                }
                else
                {
                    EditorGUI.PropertyField(position, property, label, false);
                }

                if (readOnlyAttribute != null)
                {
                    GUI.enabled = true;
                }
            }
        }