Exemplo n.º 1
0
    public static void nullCheckedField(Rect position, SerializedProperty property, GUIContent label, bool showWarning)
    {
        if (!showWarning)
        {
            EditorGUI.PropertyField(position, property, label);
            return;
        }

        GUI.backgroundColor = Color.red;

        string fillButtonText;
        var    fillCandidate = FindNonNull.findObjectToFill(property, out fillButtonText);

        if (fillCandidate == null)
        {
            EditorGUI.PropertyField(position, property, label);
            GUI.backgroundColor = Color.white;
            return;
        }

        var propertyRect = new Rect {
            x = position.x, y = position.y, width = position.width - 45, height = position.height
        };
        var buttonRect = new Rect {
            x = position.x + propertyRect.width + 8, y = position.y, width = 45 - 8, height = position.height
        };

        EditorGUI.PropertyField(propertyRect, property, label);

        GUI.backgroundColor = Color.white;
        if (GUI.Button(buttonRect, fillButtonText))
        {
            property.objectReferenceValue = fillCandidate;
        }
    }
Exemplo n.º 2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        var showWarning = (
            property.propertyType == SerializedPropertyType.ObjectReference &&
            property.objectReferenceValue == null &&
            FindNonNull.classHasAttributeOfType(property.serializedObject.targetObject.GetType(), typeof(NonNullAttribute))
            );

        NullFieldGUI.nullCheckedField(position, property, label, showWarning);
        EditorGUI.EndProperty();
    }