public override void OnGUILayout(SerializedProperty property, GUIContent label)
 {
     if (CheckValue(property))
     {
         BetterGUILayout.PropertyField(property);
     }
 }
        public override void OnGUILayout(SerializedProperty property, GUIContent label)
        {
            var prevGUIState = GUI.enabled;

            GUI.enabled = false;
            BetterGUILayout.PropertyField(property, label);
            GUI.enabled = prevGUIState;
        }
        public override void OnGUILayout(SerializedProperty property, GUIContent label)
        {
            var attr = attribute as ForkNameAttribute;

            Assert.IsNotNull(attr);
            BetterGUILayout.PropertyField(
                property,
                new GUIContent(
                    CheckValue(property)
                        ? attr.trueForkName
                        : attr.falseForkName
                    )
                );
        }
        public override void OnGUILayout(SerializedProperty property, GUIContent label)
        {
            var name = property.displayName.Split(' ');

            if (name[0] is "Element")
            {
                var attr = attribute as ElementNameAttribute;
                Assert.IsNotNull(attr);
                BetterGUILayout.PropertyField(property, new GUIContent($"{attr.name ?? "Element"} {name[1]}"), true);
            }
            else
            {
                BetterGUILayout.PropertyField(property, new GUIContent(property.displayName), true);
            }
        }
 public override void OnGUILayout(SerializedProperty property, GUIContent label)
 {
     label.text = displayName;
     label      = BetterGUILayout.BeginProperty(label, property);
     BetterGUILayout.PropertyField(property, label);
     if (property.propertyType != SerializedPropertyType.ObjectReference) // 若母標不是 UnityObject 則單純視為 PropertyField
     {
         BetterGUILayout.EndProperty();
         return;
     }
     if (IsGUI)
     {
         property.isExpanded = BetterGUILayout.Foldout(property.isExpanded, "", true);
     }
     if (property.isExpanded)
     {
         var data = property.objectReferenceValue;
         if (data is null)
         {
             return;
         }
         var dataSO = new SerializedObject(data);
         var dataSP = dataSO.GetIterator();
         EditorGUI.indentLevel++;
         dataSP.NextVisible(true);
         if (!attr.skipScriptField)
         {
             BetterGUILayout.ReadOnlyScope(() =>
             {
                 BetterGUILayout.PropertyField(dataSP);
             });
         }
         BetterGUILayout.BeginChangeCheck();
         while (dataSP.NextVisible(false))
         {
             if (!attr.skipFieldNames.Contains(dataSP.name))
             {
                 BetterGUILayout.PropertyField(dataSP);
             }
         }
         if (BetterGUILayout.EndChangeCheck())
         {
             dataSP.serializedObject.ApplyModifiedProperties();
         }
         EditorGUI.indentLevel--;
     }
     BetterGUILayout.EndProperty();
 }
Exemplo n.º 6
0
        public override void OnGUILayout(SerializedProperty property, GUIContent label)
        {
            if (property.isExpanded)
            {
                LayoutContainer(() => reorderableList.DoList(position), reorderableList.GetHeight());
                if (IsGUI)
                {
                    var newDataSP  = property.FindPropertyRelative("newData");
                    var newKeySP   = newDataSP.FindPropertyRelative("key");
                    var newValueSP = newDataSP.FindPropertyRelative("value");
                    var rect       = position;
                    rect.width = rect.width - 70F;
                    rect.yMin  = rect.yMax - 18F;
                    const float arrowWidth  = 20;
                    const float prefixWidth = 65F;

                    var keyWidth   = (rect.width - arrowWidth - prefixWidth) * 0.3F;
                    var valueWidth = rect.width - keyWidth - arrowWidth - prefixWidth;
                    EditorGUI.LabelField(
                        new Rect(rect.xMin, rect.yMin, prefixWidth, rect.height),
                        new GUIContent("New Data")
                        );
                    rect.xMin += prefixWidth;
                    EditorGUI.PropertyField(
                        new Rect(rect.xMin, rect.yMin, keyWidth, rect.height),
                        newKeySP, GUIContent.none
                        );
                    rect.xMin += keyWidth;
                    EditorGUI.PrefixLabel(
                        new Rect(rect.xMin, rect.yMin, arrowWidth, rect.height),
                        new GUIContent(ArrowText)
                        );
                    rect.xMin += arrowWidth;
                    EditorGUI.PropertyField(
                        new Rect(rect.xMin, rect.yMin, valueWidth, rect.height),
                        newValueSP, GUIContent.none
                        );
                }
            }
            else
            {
                BetterGUILayout.PropertyField(property, displayLabel);
            }
        }
 public override void OnGUILayout(SerializedProperty property, GUIContent label)
 {
     if (property.isExpanded)
     {
         LayoutContainer(() => reorderableList.DoList(position), reorderableList.GetHeight());
         if (IsGUI)
         {
             var newDataSP = property.FindPropertyRelative("newData");
             var rect      = position;
             rect.width -= 70F;
             rect.yMin   = rect.yMax - 18F;
             EditorGUI.PropertyField(rect, newDataSP);
         }
     }
     else
     {
         BetterGUILayout.PropertyField(property, displayLabel);
     }
 }
        public override void OnGUILayout(SerializedProperty property, GUIContent label)
        {
            var attr = attribute as DisplayNameAttribute;

            BetterGUILayout.PropertyField(property, new GUIContent($"{attr?.name}"), true);
        }
Exemplo n.º 9
0
        public override void OnInit(SerializedProperty property, GUIContent label)
        {
            transparentStyle = new GUIStyle
            {
                normal = { background = TextureFactory.SolidColor(new Color32(0, 0, 0, 0)) }
            };
            // set display label
            var newDataSP = property.FindPropertyRelative("newData");
            var keyType   = newDataSP.FindPropertyRelative("key").type;

            keyType = keyType.Substring("PPtr<$", ">", out var k) ? k : keyType;
            var valueType = newDataSP.FindPropertyRelative("value").type;

            valueType    = valueType.Substring("PPtr<$", ">", out var v) ? v : keyType;
            displayLabel = new GUIContent($"{label.text}  ({keyType}, {valueType})");
            //
            var valuesSP = property.FindPropertyRelative("values");

            reorderableList = new ReorderableList(valuesSP.serializedObject, valuesSP)
            {
                drawHeaderCallback = rect =>
                {
                    if (GUI.Button(rect, "", headerStyle))
                    {
                        property.isExpanded = false;
                    }
                    EditorGUI.LabelField(rect, displayLabel, headerStyle);
                },
                drawElementCallback = (rect, index, selected, focused) =>
                {
                    var         pairSP     = valuesSP.GetArrayElementAtIndex(index);
                    var         keySP      = pairSP.FindPropertyRelative("key");
                    var         valueSP    = pairSP.FindPropertyRelative("value");
                    const float arrowWidth = 20;
                    var         keyWidth   = (rect.width - arrowWidth) * 0.3F;
                    var         valueWidth = rect.width - keyWidth - arrowWidth;
                    BetterGUILayout.ReadOnlyScope(() =>
                    {
                        EditorGUI.PropertyField(
                            new Rect(rect.xMin, rect.yMin, keyWidth, rect.height),
                            keySP,
                            GUIContent.none
                            );
                    });
                    EditorGUI.PrefixLabel(
                        new Rect(rect.xMin + keyWidth, rect.yMin, arrowWidth, rect.height),
                        new GUIContent(ArrowText)
                        );
                    EditorGUI.PropertyField(
                        new Rect(rect.xMax - valueWidth, rect.yMin, valueWidth, rect.height),
                        valueSP,
                        GUIContent.none
                        );
                },
                onAddCallback = list =>
                {
                    ReorderableList.defaultBehaviours.DoAddButton(list);
                },
                onRemoveCallback = list =>
                {
                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                },
            };
        }