/// <summary> /// Displays a font property field. /// </summary> /// <param name="position">Position.</param> /// <param name="fontProperty">Font property.</param> /// <param name="inheritingFrom">Style sheet from which the font is potentially inheriting.</param> public static void DisplayFontProperty( Rect position, SerializedProperty fontProperty, HyperTextStyles inheritingFrom ) { ValidationStatus status = ValidationStatus.None; s_ReusableLabel.text = fontProperty.displayName; s_ReusableLabel.tooltip = string.Empty; if (fontProperty.objectReferenceValue == null) { if (inheritingFrom != null && inheritingFrom.CascadedFont != null) { s_ReusableLabel.tooltip = string.Format( "Inheriting Font {0} from {1}.", inheritingFrom.CascadedFont.name, inheritingFrom.name ); } else { s_ReusableLabel.tooltip = "Font cannot be null."; status = ValidationStatus.Error; } } else if (!(fontProperty.objectReferenceValue as Font).dynamic) { s_ReusableLabel.tooltip = "Font size and style settings are only supported for dynamic fonts. " + "Only colors and offsets will be applied."; status = ValidationStatus.Warning; } else if (inheritingFrom != null && inheritingFrom.CascadedFont != null) { s_ReusableLabel.tooltip = string.Format( "Overriding Font {0} inherited from {1}.", inheritingFrom.CascadedFont.name, inheritingFrom.name ); status = ValidationStatus.Warning; } if ( string.IsNullOrEmpty(s_ReusableLabel.tooltip) && inheritingFrom != null && inheritingFrom.CascadedFont != null ) { s_ReusableLabel.tooltip = string.Format( "Assign a value to override Font {0} inherited from {1}", inheritingFrom.CascadedFont.name, inheritingFrom.name ); } switch (status) { case ValidationStatus.None: EditorGUI.PropertyField(position, fontProperty, s_ReusableLabel); break; default: EditorGUIX.DisplayPropertyFieldWithStatus( position, fontProperty, status, s_ReusableLabel, false, s_ReusableLabel.tooltip ); break; } }
/// <summary> /// Raises the GUI event. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Initialize(property); SerializedProperty inputText = property.FindPropertyRelative("m_InputText"); SerializedProperty styles = property.FindPropertyRelative("m_Styles"); SerializedProperty supportRichText = property.FindPropertyRelative("m_IsRichTextDesired"); Rect entirePosition = position; position.height = (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 2f; EditorGUI.PropertyField(position, inputText); position.x = entirePosition.x; position.width = entirePosition.width; position.y += position.height + EditorGUIUtility.standardVerticalSpacing; position.height = EditorGUIUtility.singleLineHeight; EditorGUIX.DisplayScriptableObjectPropertyFieldWithButton <HyperTextStyles>(position, styles); position.y += position.height + EditorGUIUtility.standardVerticalSpacing; HyperTextEditor.DisplayOverridableProperty( position, property.FindPropertyRelative("m_ReferenceFontSize"), property.FindPropertyRelative("m_ShouldOverrideStylesFontSize"), styles ); position.x = entirePosition.x; position.width = entirePosition.width; position.y += position.height + EditorGUIUtility.standardVerticalSpacing; EditorGUIX.DisplayPropertyFieldWithStatus( position, supportRichText, ValidationStatus.Info, new GUIContent("Output Rich Text"), true, "Disable if the destination does not support rendering rich text." ); position.y += position.height + EditorGUIUtility.standardVerticalSpacing; ++EditorGUI.indentLevel; EditorGUIX.DisplayPropertyFieldWithStatus( position, property.FindPropertyRelative("m_IsDynamicFontDesired"), supportRichText.boolValue ? ValidationStatus.Info : ValidationStatus.Warning, new GUIContent("<size> Tags"), true, string.Format( "Disable if the destination uses a non-dynamic font.{0}", supportRichText.boolValue ? "" : "\n\nYou must enable rich text to output <size> tags." ) ); --EditorGUI.indentLevel; position.y += position.height + EditorGUIUtility.standardVerticalSpacing; position.height = m_LinkCollections[property.propertyPath].GetHeight(); m_LinkCollections[property.propertyPath].DoList(position); position.y += position.height; position.height = m_TagCollections[property.propertyPath].GetHeight(); m_TagCollections[property.propertyPath].DoList(position); position.y += position.height; position.height = m_QuadCollections[property.propertyPath].GetHeight(); m_QuadCollections[property.propertyPath].DoList(position); }
/// <summary> /// Raises the inspector GUI event. /// </summary> public override void OnInspectorGUI() { this.serializedObject.Update(); m_AssignedCollections = HyperTextProcessorDrawer.GetAllCollections(m_TextProcessorProperty); EditorGUILayout.PropertyField(m_ScriptProperty); EditorGUILayout.PropertyField(m_InteractableProperty); Rect position = EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(m_LinkHitboxPaddingProperty)); DisplayOverridableProperty( position, m_LinkHitboxPaddingProperty, m_OverrideLinkHitboxProperty, m_StylesProperty ); bool hadStyles = m_StylesProperty.objectReferenceValue != null; if (EditorGUIX.DisplayScriptableObjectPropertyFieldWithButton <HyperTextStyles>(m_StylesProperty)) { HyperTextStyles newStyles = m_StylesProperty.objectReferenceValue as HyperTextStyles; if (newStyles != null && m_FontDataProperty.FindPropertyRelative("m_Font").objectReferenceValue != null) { newStyles.Font = m_FontDataProperty.FindPropertyRelative("m_Font").objectReferenceValue as Font; } } if ( !hadStyles && m_StylesProperty.objectReferenceValue != null && (m_StylesProperty.objectReferenceValue as HyperTextStyles).CascadedFont != null ) { m_FontDataProperty.FindPropertyRelative("m_Font").objectReferenceValue = null; } // NOTE: LayoutList() doesn't use proper vertical spacing Rect rect = EditorGUILayout.GetControlRect(false, m_LinkKeywordCollections.GetHeight()); m_LinkKeywordCollections.DoList(rect); rect = EditorGUILayout.GetControlRect(false, m_TagKeywordCollections.GetHeight()); m_TagKeywordCollections.DoList(rect); rect = EditorGUILayout.GetControlRect(false, m_QuadKeywordCollections.GetHeight()); m_QuadKeywordCollections.DoList(rect); bool isTextInputSourceAssigned = m_InputTextSourceProperty.objectReferenceValue != null || (this.target as HyperText).InputTextSource != null; EditorGUI.BeginDisabledGroup(isTextInputSourceAssigned); { EditorGUILayout.PropertyField(m_TextProperty); } EditorGUI.EndDisabledGroup(); if (isTextInputSourceAssigned) { EditorGUIX.DisplayPropertyFieldWithStatus( m_InputTextSourceProperty, ValidationStatus.Warning, s_InputTextSourceLabel, false, s_InputTextSourceLabel.tooltip ); } else { EditorGUILayout.PropertyField(m_InputTextSourceProperty, s_InputTextSourceLabel); } EditorGUILayout.LabelField("Character", EditorStyles.boldLabel); ++EditorGUI.indentLevel; position = EditorGUILayout.GetControlRect(); DisplayFontProperty(position, m_FontProperty, m_StylesProperty.objectReferenceValue as HyperTextStyles); position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty(position, m_FontStyleProperty, m_OverrideFontStyleProperty, m_StylesProperty); position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty(position, m_FontSizeProperty, m_OverrideFontSizeProperty, m_StylesProperty); position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty( position, m_LineSpacingProperty, m_OverrideLineSpacingProperty, m_StylesProperty ); EditorGUILayout.PropertyField(m_RichTextProperty); --EditorGUI.indentLevel; EditorGUILayout.LabelField("Paragraph", EditorStyles.boldLabel); ++EditorGUI.indentLevel; EditorGUILayout.PropertyField(m_AlignmentProperty); EditorGUILayout.PropertyField(m_HorizontalOverflowProperty); EditorGUILayout.PropertyField(m_VerticalOverflowProperty); EditorGUILayout.PropertyField(m_BestFitProperty); --EditorGUI.indentLevel; position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty(position, m_ColorProperty, m_OverrideFontColorProperty, m_StylesProperty); EditorGUILayout.PropertyField(m_MaterialProperty, s_MaterialLabel); EditorGUILayout.LabelField("Events", EditorStyles.boldLabel); EditorGUILayout.PropertyField(m_OnClickProperty); EditorGUILayout.PropertyField(m_OnEnterProperty); EditorGUILayout.PropertyField(m_OnExitProperty); EditorGUILayout.PropertyField(m_OnPressProperty); EditorGUILayout.PropertyField(m_OnReleaseProperty); this.serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Raises the inspector GUI event. /// </summary> public override void OnInspectorGUI() { this.serializedObject.Update(); m_AssignedCollections = HyperTextProcessorDrawer.GetAllCollections(m_TextProcessor); EditorGUILayout.PropertyField(m_Script); if ( m_RaycastTargetWarningStatus != ValidationStatus.None && DisplayErrorMessageWithFixButton( m_RaycastTargetWarningMessage, s_FixRaycastTargetLabel, m_RaycastTargetWarningStatus == ValidationStatus.Warning ? MessageType.Warning : MessageType.Error ) ) { m_RaycastTarget.boolValue = !m_RaycastTarget.boolValue; this.serializedObject.ApplyModifiedProperties(); } EditorGUILayout.PropertyField(m_Interactable); ++EditorGUI.indentLevel; EditorGUI.BeginDisabledGroup(!m_Interactable.boolValue); { EditorGUILayout.PropertyField(m_OpenURLPatterns, s_OpenURLPatternsLabel); } EditorGUI.EndDisabledGroup(); --EditorGUI.indentLevel; Rect position = EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(m_LinkHitboxPadding)); DisplayOverridableProperty( position, m_LinkHitboxPadding, m_ShouldOverrideStylesLinkHitboxPadding, m_Styles ); bool hadStyles = m_Styles.objectReferenceValue != null; if (EditorGUIX.DisplayScriptableObjectPropertyFieldWithButton <HyperTextStyles>(m_Styles)) { HyperTextStyles newStyles = m_Styles.objectReferenceValue as HyperTextStyles; if (newStyles != null) { if (m_Font.objectReferenceValue != null) { newStyles.Font = m_Font.objectReferenceValue as Font; } newStyles.DefaultFontStyle = (FontStyle)m_FontStyle.enumValueIndex; newStyles.DefaultTextColor = m_Color.colorValue; newStyles.FontSize = m_FontSize.intValue; } } if ( !hadStyles && m_Styles.objectReferenceValue != null && (m_Styles.objectReferenceValue as HyperTextStyles).CascadedFont != null ) { m_Font.objectReferenceValue = null; } // NOTE: LayoutList() doesn't use proper vertical spacing ++EditorGUI.indentLevel; int indent = EditorGUI.indentLevel; Rect rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(false, m_LinkKeywordCollections.GetHeight())); EditorGUI.indentLevel = 0; m_LinkKeywordCollections.DoList(rect); EditorGUI.indentLevel = indent; rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(false, m_TagKeywordCollections.GetHeight())); EditorGUI.indentLevel = 0; m_TagKeywordCollections.DoList(rect); EditorGUI.indentLevel = indent; rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(false, m_QuadKeywordCollections.GetHeight())); EditorGUI.indentLevel = 0; m_QuadKeywordCollections.DoList(rect); EditorGUI.indentLevel = indent; --EditorGUI.indentLevel; bool isTextInputSourceAssigned = m_InputTextSourceObject.objectReferenceValue != null || (this.target as HyperText).InputTextSource != null; EditorGUI.BeginDisabledGroup(isTextInputSourceAssigned); { EditorGUI.BeginChangeCheck(); { EditorGUILayout.PropertyField(m_Text); } if (EditorGUI.EndChangeCheck()) { ApplyModificationsAndUpdateGUIContents(); } } EditorGUI.EndDisabledGroup(); if (isTextInputSourceAssigned) { EditorGUIX.DisplayPropertyFieldWithStatus( m_InputTextSourceObject, ValidationStatus.Warning, s_InputTextSourceLabel, false, s_InputTextSourceLabel.tooltip ); } else { EditorGUILayout.PropertyField(m_InputTextSourceObject, s_InputTextSourceLabel); } EditorGUILayout.LabelField("Character", EditorStyles.boldLabel); ++EditorGUI.indentLevel; position = EditorGUILayout.GetControlRect(); DisplayFontProperty(position, m_Font, m_Styles.objectReferenceValue as HyperTextStyles); position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty(position, m_FontStyle, m_ShouldOverrideStylesFontStyle, m_Styles); position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty(position, m_FontSize, m_ShouldOverrideStylesFontSize, m_Styles); position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty( position, m_LineSpacing, m_ShouldOverrideStylesLineSpacing, m_Styles ); EditorGUILayout.PropertyField(m_RichText); --EditorGUI.indentLevel; EditorGUILayout.LabelField("Paragraph", EditorStyles.boldLabel); ++EditorGUI.indentLevel; EditorGUILayout.PropertyField(m_Alignment); if (m_AlignByGeometry != null) { EditorGUILayout.PropertyField(m_AlignByGeometry); } EditorGUILayout.PropertyField(m_HorizontalOverflow); EditorGUILayout.PropertyField(m_VerticalOverflow); EditorGUILayout.PropertyField(m_BestFit); if (m_BestFit.boolValue) { ++EditorGUI.indentLevel; EditorGUILayout.PropertyField(m_MinSize); EditorGUILayout.PropertyField(m_MaxSize); --EditorGUI.indentLevel; } --EditorGUI.indentLevel; position = EditorGUILayout.GetControlRect(); DisplayOverridableProperty(position, m_Color, m_ShouldOverrideStylesFontColor, m_Styles); EditorGUILayout.PropertyField(m_Material, s_MaterialLabel); EditorGUILayout.PropertyField(m_QuadMaterial); EditorGUI.BeginChangeCheck(); { EditorGUILayout.PropertyField(m_RaycastTarget); if (!string.IsNullOrEmpty(m_RaycastTargetWarningMessage)) { position = GUILayoutUtility.GetLastRect(); position.x += position.width - EditorGUIUtility.singleLineHeight; position.width = EditorGUIUtility.singleLineHeight; EditorGUIX.DisplayValidationStatusIcon( position, m_RaycastTargetWarningStatus, m_RaycastTargetWarningMessage ); } } if (EditorGUI.EndChangeCheck()) { ApplyModificationsAndUpdateGUIContents(); } if (m_SubclassProperties.Count > 0) { EditorGUILayout.LabelField("Other Properties", EditorStyles.boldLabel); ++EditorGUI.indentLevel; for (int i = 0; i < m_SubclassProperties.Count; ++i) { EditorGUILayout.PropertyField(m_SubclassProperties[i]); } --EditorGUI.indentLevel; } EditorGUILayout.LabelField("Events", EditorStyles.boldLabel); ++EditorGUI.indentLevel; DisplayEventProperty(m_ClickedLink); DisplayEventProperty(m_EnteredLink); DisplayEventProperty(m_ExitedLink); DisplayEventProperty(m_PressedLink); DisplayEventProperty(m_ReleasedLink); --EditorGUI.indentLevel; this.serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Raises the draw keyword collection class entry event. /// </summary> /// <param name="position">Position.</param> /// <param name="element">Element in the list.</param> /// <param name="identifierGUIContent">Identifier GUI content.</param> /// <param name="existingIdentifierNames">Existing identifier names.</param> /// <param name="defaultStatus">Default status.</param> /// <param name="missingStyleDescriptor">Missing style descriptor.</param> /// <param name="styles">Styles assigned to the <see cref="Candlelight.UI.HyperTextProcessor"/>.</param> /// <param name="assignedCollections"> /// All <see cref="Candlelight.KeywordCollection"/> objects assigned to the /// <see cref="Candlelight.UI.HyperTextProcessor"/>. /// </param> private static void OnDrawKeywordCollectionClassEntry( Rect position, SerializedProperty element, GUIContent identifierGUIContent, IEnumerable <string> existingIdentifierNames, ValidationStatus defaultStatus, string missingStyleDescriptor, HyperTextStyles styles, IEnumerable <KeywordCollection> assignedCollections ) { SerializedProperty collectionProperty = element.FindPropertyRelative("m_Collection"); ValidationStatus collectionStatus = ValidationStatus.Warning; if (collectionProperty.objectReferenceValue != null) { collectionStatus = assignedCollections.Count(item => item == collectionProperty.objectReferenceValue) > 1 ? ValidationStatus.Error : ValidationStatus.Okay; } string collectionTooltip; switch (collectionStatus) { case ValidationStatus.Error: collectionTooltip = "Specified keyword collection used for multiple different styles on this object."; break; case ValidationStatus.Warning: collectionTooltip = "Assign a keyword collection to automatically apply this style to keywords."; break; default: collectionTooltip = string.Empty; break; } string identifierName = element.FindPropertyRelative("m_ClassName").stringValue; ValidationStatus identifierStatus = defaultStatus; string identifierTooltip = string.Empty; if (!string.IsNullOrEmpty(identifierName)) { if (styles == null) { identifierTooltip = "No styles assigned to this object. Keywords from this collection will use default style"; identifierStatus = ValidationStatus.Warning; } else { int matches = existingIdentifierNames.Count(existingId => existingId == identifierName); if (matches == 1) { identifierStatus = ValidationStatus.Okay; } else { identifierStatus = ValidationStatus.Error; identifierTooltip = string.Format( "No custom {0} {1} found in {2}.", missingStyleDescriptor, identifierName, styles.name ); } } } bool useCollectionStatus = collectionStatus >= identifierStatus; EditorGUIX.DisplayPropertyFieldWithStatus( position, element, useCollectionStatus ? collectionStatus : identifierStatus, null, true, useCollectionStatus ? collectionTooltip : identifierTooltip ); }
/// <summary> /// Raises the draw keyword collection class entry event. /// </summary> /// <param name="position">Position.</param> /// <param name="element">Element in the list.</param> /// <param name="identifierGUIContent">Identifier GUI content.</param> /// <param name="existingIdentifierNames">Existing identifier names.</param> /// <param name="defaultStatus">Default status.</param> /// <param name="infoTooltip">Info tooltip.</param> /// <param name="missingStyleDescriptor">Missing style descriptor.</param> /// <param name="styles">Styles assigned to the <see cref="Candlelight.UI.HyperTextProcessor"/>.</param> /// <param name="assignedCollections"> /// All <see cref="Candlelight.KeywordCollection"/> objects assigned to the /// <see cref="Candlelight.UI.HyperTextProcessor"/>. /// </param> private static void OnDrawKeywordCollectionClassEntry( Rect position, SerializedProperty element, GUIContent identifierGUIContent, IEnumerable <string> existingIdentifierNames, ValidationStatus defaultStatus, string infoTooltip, string missingStyleDescriptor, HyperTextStyles styles, IEnumerable <KeywordCollection> assignedCollections ) { position.height = EditorGUIUtility.singleLineHeight; float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 60f; position.width = (position.width - EditorGUIX.standardHorizontalSpacing) * 0.6f; SerializedProperty collectionProperty = element.FindPropertyRelative("m_Collection"); ValidationStatus collectionStatus = ValidationStatus.Warning; if (collectionProperty.objectReferenceValue != null) { collectionStatus = assignedCollections.Count(item => item == collectionProperty.objectReferenceValue) > 1 ? ValidationStatus.Error : ValidationStatus.Okay; } EditorGUIX.DisplayPropertyFieldWithStatus( position, collectionProperty, collectionStatus, null, true, collectionStatus == ValidationStatus.Okay ? "" : collectionStatus == ValidationStatus.Error ? string.Format( "Keyword collection {0} used for multiple different styles on this object.", collectionProperty.objectReferenceValue.name ) : "Assign a keyword collection to automatically apply this style to keywords." ); EditorGUIUtility.labelWidth = 40f; position.x += position.width; position.width *= 0.6666666667f; string identifierName = element.FindPropertyRelative("m_ClassName").stringValue; ValidationStatus status = defaultStatus; if (!string.IsNullOrEmpty(identifierName)) { if (styles == null) { infoTooltip = "No styles assigned to this object. Keywords from this collection will use default style"; status = ValidationStatus.Warning; } else { int matches = existingIdentifierNames.Count(existingId => existingId == identifierName); if (matches == 1) { status = ValidationStatus.Okay; infoTooltip = string.Empty; } else { status = ValidationStatus.Error; infoTooltip = string.Format( "No custom {0} {1} found in {2}.", missingStyleDescriptor, identifierName, styles.name ); } } } EditorGUIX.DisplayPropertyFieldWithStatus( position, element.FindPropertyRelative("m_ClassName"), status, identifierGUIContent, true, infoTooltip ); EditorGUIUtility.labelWidth = oldLabelWidth; }