Ejemplo n.º 1
0
    public override float GetPropertyHeight(SerializedProperty _property, GUIContent _label)
    {
        ShowInInspectorIf showInInspector = (ShowInInspectorIf)attribute;
        bool enabled = ShouldShow(showInInspector, _property);

        if (enabled)
        {
            return(EditorGUI.GetPropertyHeight(_property, _label));
        }
        else
        {
            return(-EditorGUIUtility.standardVerticalSpacing);
        }
    }
Ejemplo n.º 2
0
    public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label)
    {
        ShowInInspectorIf showInInspector = (ShowInInspectorIf)attribute;
        bool enabled    = ShouldShow(showInInspector, _property);
        bool wasEnabled = GUI.enabled;

        GUI.enabled = enabled;
        if (enabled)
        {
            ++EditorGUI.indentLevel;
            EditorGUI.PropertyField(_position, _property, _label, true);
            --EditorGUI.indentLevel;
        }

        GUI.enabled = wasEnabled;
    }
Ejemplo n.º 3
0
    private bool ShouldShow(ShowInInspectorIf _attribute, SerializedProperty _property)
    {
        bool               enabled             = true;
        string             propertyPath        = _property.propertyPath;
        string             conditionPath       = propertyPath.Replace(_property.name, _attribute.conditionalSourceField);
        SerializedProperty sourcePropertyValue = _property.serializedObject.FindProperty(conditionPath);

        if (sourcePropertyValue != null)
        {
            enabled = sourcePropertyValue.boolValue == _attribute.compare;
        }
        else
        {
            Debug.LogWarning("Attempting to use ShowInInspectorIf but no matching SourcePropertyValue found in object: " + _attribute.conditionalSourceField);
        }

        return(enabled);
    }