private bool IsComparisonValid(SerializedProperty property) { System.Object objectInstance = property.GetTargetObjectWithProperty(); var comparisonAttribute = attribute as ConditionalAttribute; FieldInfo field = objectInstance.GetField(comparisonAttribute.PropertyName); PropertyInfo nonSerializedMember = objectInstance.GetProperty(comparisonAttribute.PropertyName); var objectValue = field != null?field.GetValue(objectInstance) : nonSerializedMember.GetValue(objectInstance); if (!objectValue.ToBool(out bool memberValue)) { Debug.LogError($"Value {objectValue} is not a boolean"); } if (comparisonAttribute.TargetConditionValue == null) { return(memberValue); } if (!comparisonAttribute.TargetConditionValue.ToBool(out bool targetConditionValue)) { Debug.LogError($"Value {comparisonAttribute.TargetConditionValue} is not a boolean"); } return(memberValue == targetConditionValue); }
private void HighlightUsingProperty(Rect position, SerializedProperty property, GUIContent label) { var highlightAttribute = attribute as HighlightAttribute; System.Object objectInstance = property.GetTargetObjectWithProperty(); FieldInfo field = objectInstance.GetField(highlightAttribute.TargetPropertyName); PropertyInfo nonSerializedMember = objectInstance.GetProperty(highlightAttribute.TargetPropertyName); var objectValue = field != null?field.GetValue(objectInstance) : nonSerializedMember.GetValue(objectInstance); if (!objectValue.ToBool(out bool memberValue)) { var message = $"Value {objectValue} is not a boolean"; DrawErrorMessage(position, message); return; } if (memberValue) { HighlightField(position, property, label); } else { DrawProperty(position, property, label); } }