/// <summary> /// Displays a property field with an optional override property checkbox and status icon as needed. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> /// <param name="overrideProperty"> /// Property specifying whether the other property is overriding an inherited one. Object reference properties /// are assumed to override if they have a value assigned. /// </param> /// <param name="displayCheckbox">If set to <see langword="true"/> display checkbox/tooltip as needed.</param> /// <param name="inheritTooltip">Predicate fragment of the tooltip when property is inheriting.</param> /// <param name="overrideTooltip">Predicate fragment of the tooltip when property is overridden.</param> public static void DisplayOverridableProperty( Rect position, SerializedProperty property, SerializedProperty overrideProperty, bool displayCheckbox, string inheritTooltip, string overrideTooltip ) { if (displayCheckbox) { ValidationStatus status = ValidationStatus.None; if (property.propertyType == SerializedPropertyType.ObjectReference) { status = property.objectReferenceValue == null ? ValidationStatus.None : ValidationStatus.Warning; } else { status = overrideProperty.hasMultipleDifferentValues || overrideProperty.boolValue ? ValidationStatus.Warning : ValidationStatus.None; } s_ReusableLabel.text = property.displayName; s_ReusableLabel.tooltip = string.Format( property.serializedObject.isEditingMultipleObjects ? "{0} {1} on at least one selected object." : "{0} {1}.", property.displayName, status == ValidationStatus.Warning ? overrideTooltip : inheritTooltip ); if (status != ValidationStatus.None) { Rect iconPosition = position; iconPosition.x += position.width - EditorGUIUtility.singleLineHeight; iconPosition.width = iconPosition.height = EditorGUIUtility.singleLineHeight; if (property.propertyType != SerializedPropertyType.Generic) { position.width -= iconPosition.width; } EditorGUIX.DisplayValidationStatusIcon(iconPosition, status, s_ReusableLabel.tooltip); } if (property.propertyType == SerializedPropertyType.ObjectReference) { EditorGUI.PropertyField(position, property, s_ReusableLabel); } else { EditorGUIX.DisplayPropertyWithToggle(position, s_ReusableLabel, overrideProperty, property); } } else { EditorGUI.PropertyField(position, property); } }