示例#1
0
    /// <summary>
    /// Draw the inspector
    /// </summary>
    /// <param name="position"></param>
    /// <param name="property"></param>
    /// <param name="label"></param>
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label = EditorGUI.BeginProperty(position, label, property);

        //Get display attribute
        DisplayIfAttribute displayAttribute = (DisplayIfAttribute)attribute;
        bool enabled = displayAttribute.ShouldDisplay(property.serializedObject);

        //Enable/disable the property
        bool wasEnabled = GUI.enabled;

        GUI.enabled = enabled;

        EditorGUI.BeginChangeCheck();

        if (enabled)
        {
            EditorGUI.PropertyField(position, property, label, true);
        }

        EditorGUI.EndChangeCheck();

        //Ensure that the next property that is being drawn uses the correct settings
        GUI.enabled = wasEnabled;

        EditorGUI.EndProperty();
    }
示例#2
0
    /// <summary>
    /// Override the get height method
    /// </summary>
    /// <param name="property"></param>
    /// <param name="label"></param>
    /// <returns></returns>
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        //Get display attribute
        DisplayIfAttribute displayAttribute = (DisplayIfAttribute)attribute;
        bool enabled = displayAttribute.ShouldDisplay(property.serializedObject);

        if (enabled)
        {
            return(base.GetPropertyHeight(property, label));
        }
        else
        {
            return(0f);
        }
    }