public override float GetPropertyHeight(SerializedProperty _property, GUIContent _label) { ShowOnEnum showInInspector = (ShowOnEnum)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) { ShowOnEnum showInInspector = (ShowOnEnum)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(ShowOnEnum _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) { //Debug.Log("ShowOnEnum name = " + _attribute.conditionalSourceField + ", compare = " + _attribute.compare + ", value = " + sourcePropertyValue.intValue); enabled = sourcePropertyValue.intValue == _attribute.compare; } else { Debug.LogWarning("Attempting to use ShowOnEnumValue but no matching SourcePropertyValue found in object: " + _attribute.conditionalSourceField); } return(enabled); }