Exemplo n.º 1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Foldable foldableAttribute = (Foldable)attribute;

        SerializedProperty disablingProperty = null;

        if (foldableAttribute.CanBeDisabled)
        {
            var parentProperty = SerializableObjectHelper.GetParentProperty(property);
            disablingProperty = parentProperty.FindPropertyRelative(foldableAttribute.DisablingBoolAttribute);
            if (this.foldableArea == null)
            {
                this.foldableArea = new FoldableArea(foldableAttribute.CanBeDisabled, property.name, disablingProperty.boolValue);
            }
        }
        else
        {
            if (this.foldableArea == null)
            {
                this.foldableArea = new FoldableArea(foldableAttribute.CanBeDisabled, property.name, false);
            }
        }


        EditorGUI.BeginProperty(position, null, property);
        this.foldableArea.OnGUI(() =>
        {
            try
            {
                foreach (var childPropery in SerializableObjectHelper.GetChildren(property))
                {
                    EditorGUILayout.PropertyField(childPropery, true);
                }
            }
            catch (Exception) { }
        });

        if (foldableAttribute.CanBeDisabled)
        {
            disablingProperty.boolValue = this.foldableArea.IsEnabled;
        }
        EditorGUI.EndProperty();
    }
Exemplo n.º 2
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();
    }