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); } }
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; }
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); }