public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { StringConditionalHide2 condHAtt = (StringConditionalHide2)attribute; bool enabled = GetConditionalHideAttributeResult(condHAtt, property); if (!condHAtt.HideInInspector || enabled) { return(EditorGUI.GetPropertyHeight(property, label)); } else { return(-EditorGUIUtility.standardVerticalSpacing); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { StringConditionalHide2 condHAtt = (StringConditionalHide2)attribute; bool enabled = GetConditionalHideAttributeResult(condHAtt, property); bool wasEnabled = GUI.enabled; GUI.enabled = enabled; if (!condHAtt.HideInInspector || enabled) { EditorGUI.PropertyField(position, property, label, true); } GUI.enabled = wasEnabled; }
private bool GetConditionalHideAttributeResult(StringConditionalHide2 condHAtt, SerializedProperty property) { bool enabled = true; string propertyPath = property.propertyPath; //returns the property path of the property we want to apply the attribute to string conditionPath = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField); //changes the path to the conditionalsource property path SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath); if (sourcePropertyValue != null) { if (condHAtt.reverseCondition) { enabled = true; for (int i = 0; i < condHAtt.list.Length; i++) { if (sourcePropertyValue.stringValue == condHAtt.list [i]) { enabled = false; } } } else { enabled = false; for (int i = 0; i < condHAtt.list.Length; i++) { if (sourcePropertyValue.stringValue == condHAtt.list [i]) { enabled = true; } } } } else { Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField); } return(enabled); }