示例#1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        ReorderableListAttribute attr = (ReorderableListAttribute)attribute;
        var parentProperty            = SerializableObjectHelper.GetParentProperty(property);

        position.height *= 3;
        if (parentProperty != null && parentProperty.isArray)
        {
            if (SerializableObjectHelper.GetArrayIndex(property) == 0)
            {
                if (this.rList == null)
                {
                    this.rList = new ReorderableList(property.serializedObject, parentProperty);
                    this.rList.drawHeaderCallback = (Rect rect) =>
                    {
                        EditorGUI.LabelField(rect, SerializableObjectHelper.GetParentProperty(parentProperty).name);
                    };
                    this.rList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                    {
                        rect.y      += 2;
                        rect.height -= 5;
                        if (attr.DisplayLineLabel)
                        {
                            EditorGUI.PropertyField(rect, this.rList.serializedProperty.GetArrayElementAtIndex(index), true);
                        }
                        else
                        {
                            EditorGUI.PropertyField(rect, this.rList.serializedProperty.GetArrayElementAtIndex(index), GUIContent.none, true);
                        }
                    };
                    this.rList.elementHeightCallback = (int index) =>
                    {
                        return(EditorGUI.GetPropertyHeight(this.rList.serializedProperty.GetArrayElementAtIndex(index)) + 3);
                    };
                }
                this.rList.DoList(position);
            }
        }

        parentProperty.serializedObject.ApplyModifiedProperties();
    }
示例#2
0
    public override float GetPropertyHeight(SerializedProperty p_property, GUIContent p_label)
    {
        string _path   = p_property.propertyPath;
        float  _height = 0;
        ReorderableListAttribute _reorderableList = attribute as ReorderableListAttribute;
        bool _isFirst = _path.EndsWith(".data[0]");
        bool _isLast  = false;

        if (_reorderableList.list != null)
        {
            _isLast = _path.EndsWith(".data[" + (_reorderableList.list.count - 1) + "]");
        }
        if (useOrder && (_reorderableList.list != null))
        {
            if (_isFirst)
            {
                _height = _reorderableList.list.GetHeight() + 18;
            }
            else
            {
                _height = -2;
            }
        }
        else
        {
            _height = SerializedPropertyValue.GetPropertyHeight(p_property, p_label);
        }

        if ((_reorderableList.list != null) && !useOrder && _isLast)
        {
            return(_height + 18);
        }
        else
        {
            return(_height);
        }
    }
示例#3
0
 public ReorderableList(InspectorAttribute attribute) : base(attribute)
 {
     RAttribute = attribute as ReorderableListAttribute;
 }
示例#4
0
    public override void OnGUI(Rect p_position, SerializedProperty p_property, GUIContent p_label)
    {
        string _path = p_property.propertyPath;

        if (!_path.EndsWith("]"))
        {
            EditorGUI.LabelField(p_position, p_label.text, "[ReorderableList] Only for Array Or Collection");
            return;
        }

        ReorderableListAttribute _reorderableList = attribute as ReorderableListAttribute;
        bool _isFirst = _path.EndsWith(".data[0]");

        if (_reorderableList.list != null)
        {
            if (_isFirst)
            {
                Rect _butRect = new Rect(p_position);
                int  _indent  = EditorGUI.indentLevel * 15;
                _butRect.height = 16;
                if (useOrder)
                {
                    _butRect.x     += _indent + 70;
                    _butRect.width -= _indent + 70 + 160;
                    if (GUI.Button(_butRect, "Finish Reorder"))
                    {
                        useOrder = false;
                    }
                }
                else
                {
                    _butRect.x     += _indent;
                    _butRect.width -= _indent + 160;
                    if (GUI.Button(_butRect, "Start Reorder"))
                    {
                        useOrder = true;
                    }
                }

                _butRect.x    += _butRect.width;
                _butRect.width = 160;
                SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property);
                SerializedPropertyValue.DrawCopyPasteArray(_butRect, _parentProperty);
            }
        }

        SerializedObject _serializedObject = p_property.serializedObject;

        if (_isFirst)
        {
            if (_reorderableList.list == null)
            {
                SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property);
                _reorderableList.list = ReorderableListUtility.CreateAutoLayout(_parentProperty, 4, SerializedPropertyValue.DrawCopyPasteBehind);
            }
        }

        if (useOrder)
        {
            if (_isFirst)
            {
                p_position.width -= 120;
                ReorderableListUtility.DoListWithFoldout(_reorderableList.list, p_position);
            }
        }
        else
        {
            p_position.y += 16;

            Rect _copyPasteRect = new Rect(p_position);
            _copyPasteRect.x     += p_position.width - 120;
            _copyPasteRect.width  = 120;
            _copyPasteRect.height = 18;
            string _click = SerializedPropertyValue.DrawCopyPasteButton(_copyPasteRect, p_property);
            if (_click != "")
            {
            }
            else if ((p_property.propertyType == SerializedPropertyType.Generic) || (p_property.isArray && (p_property.propertyType != SerializedPropertyType.String)))
            {
                EditorGUI.PropertyField(p_position, p_property, p_label, true);
            }
            else
            {
                p_position.width -= 120;
                p_position.height = SerializedPropertyValue.GetPropertyHeight(p_property, p_label);
                EditorGUI.PropertyField(p_position, p_property);
            }
        }
    }