/// <summary> /// Updates the validatation status if the identifier already eixsts in the table of inherited styles. /// </summary> /// <param name="guiContent">CustomStyleGUIContent for a particular style entry.</param> /// <param name="styleIdentifier">Style identifier.</param> /// <param name="inheritedStyles">Inherited styles.</param> /// <typeparam name="T">The style type.</typeparam> private void UpdateValidatationStatusIfOverridingInheritedStyle <T>( CustomStyleGUIContent guiContent, string styleIdentifier, Dictionary <T, HyperTextStyles> inheritedStyles ) where T : IIdentifiable <string> { if (guiContent.Status != ValidationStatus.Okay) { return; } T existingStyle = inheritedStyles.Keys.Where(s => s.Identifier.ToLower() == styleIdentifier.ToLower()).FirstOrDefault(); if (existingStyle.Identifier.ToLower() == styleIdentifier.ToLower()) { guiContent.Status = ValidationStatus.Warning; guiContent.StatusTooltip = string.Format( "Overrides inherited style {0}.{1}.", inheritedStyles[existingStyle].name, existingStyle.Identifier ); } }
/// <summary> /// Validates the name of the identifier in the supplied list of styles. /// </summary> /// <returns>The validation info for the supplied identifier.</returns> /// <param name="identifier">Identifier to validate against the collection.</param> /// <param name="list">List.</param> /// <param name="identifierLabel">Label of the identifier to appear in the tooltip.</param> private CustomStyleGUIContent ValidateIdentifier <T>( string identifier, List <T> items, string identifierLabel = "Class name" ) where T : IIdentifiable <string> { CustomStyleGUIContent result = new CustomStyleGUIContent(); result.Label = new GUIContent(); result.Status = string.IsNullOrEmpty(identifier) ? ValidationStatus.Error : ValidationStatus.Okay; result.StatusTooltip = string.IsNullOrEmpty(identifier) ? string.Format("{0} must be specified.", identifierLabel) : ""; if ( result.Status == ValidationStatus.Okay && items.Where(t => t.Identifier.ToLower() == identifier.ToLower()).Count() > 1 ) { result.StatusTooltip = string.Format( "{0} \"{1}\" occurs more than once in the list of styles.", identifierLabel, identifier ); result.Status = ValidationStatus.Error; } return(result); }
/// <summary> /// Displays a validation icon next to a style's label in the inspector. /// </summary> /// <param name="elementDrawPosition">Element draw position.</param> /// <param name="info">Validation info.</param> private static void DisplayStyleIdentifierValidationIcon(Rect elementDrawPosition, CustomStyleGUIContent info) { if ( elementDrawPosition.height < (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 2f ) { elementDrawPosition.x += elementDrawPosition.width - EditorGUIUtility.singleLineHeight; } else { elementDrawPosition.x += EditorGUIUtility.labelWidth - EditorGUIUtility.singleLineHeight - EditorGUIX.StandardHorizontalSpacing; } elementDrawPosition.height = elementDrawPosition.width = EditorGUIUtility.singleLineHeight; info.Status = info.Status == ValidationStatus.Okay ? ValidationStatus.None : info.Status; EditorGUIX.DisplayValidationStatusIcon(elementDrawPosition, info.Status, info.StatusTooltip); }