Exemplo n.º 1
0
 /// <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);
     }
 }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo n.º 3
0
        /// <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();
        }