Beispiel #1
0
        private void DrawSubstringNotLeftAligned()
        {
            TextAnchor originalAlignment = GuiStyle.alignment;

            GuiStyle.alignment = GetLeftAlignedVersion(GuiStyle.alignment);
            float lineHeight = GuiStyle.CalcSize(new GUIContent(text)).y;
            float y          = rect.y;
            int   start      = 0;
            int   charsLeft  = substringLength;

            while (charsLeft > 0)
            {
                string line    = GetNextLine(text, start);
                string subLine = line.Substring(0, Mathf.Min(line.Length, charsLeft));
                start     += line.Length;
                charsLeft -= line.Length;
                float lineWidth = GuiStyle.CalcSize(new GUIContent(line.Trim())).x;
                float x         = IsCenterAligned(originalAlignment)
                                        ? Mathf.Ceil(rect.x + (0.5f * rect.width) - (0.5f * lineWidth)) + 0.5f
                                        : rect.x + rect.width - lineWidth;
                UnityGUITools.DrawText(new Rect(x, y, rect.width, lineHeight), GetRichTextClosedText(subLine.Trim()), GuiStyle, textStyle, textStyleColor);
                y += GuiStyle.lineHeight;
            }
            GuiStyle.alignment = originalAlignment;
        }
Beispiel #2
0
 private void DrawSubstring()
 {
     if (IsLeftAligned(GuiStyle.alignment))
     {
         UnityGUITools.DrawText(rect, GetRichTextClosedText(text.Substring(0, substringLength)), GuiStyle, textStyle, textStyleColor);
     }
     else
     {
         DrawSubstringNotLeftAligned();
     }
 }
Beispiel #3
0
 /// <summary>
 /// Draws the control, but not its children.
 /// </summary>
 /// <param name="relativeMousePosition">Relative mouse position within the window containing this control.</param>
 public override void DrawSelf(Vector2 relativeMousePosition)
 {
     ApplyAlphaToGUIColor();
     if (image != null)
     {
         DrawImage();
     }
     if (!string.IsNullOrEmpty(text))
     {
         if (useSubstring)
         {
             DrawSubstring();
         }
         else
         {
             UnityGUITools.DrawText(rect, text, GuiStyle, textStyle, textStyleColor);
         }
     }
     RestoreGUIColor();
 }
        /// <summary>
        /// Draws the bark text using Unity GUI.
        /// </summary>
        public virtual void OnGUI()
        {
            GUI.skin = UnityGUITools.GetValidGUISkin(guiSkin);
            if (guiStyle == null)
            {
                guiStyle           = UnityGUITools.ApplyFormatting(formattingToApply, new GUIStyle(UnityGUITools.GetGUIStyle(guiStyleName, GUI.skin.label)));
                guiStyle.alignment = TextAnchor.UpperCenter;
                size = guiStyle.CalcSize(new GUIContent(message));
                if ((maxWidth >= 1) && (size.x > maxWidth))
                {
                    size = new Vector2(maxWidth, guiStyle.CalcHeight(new GUIContent(message), maxWidth));
                }
            }
            UpdateBarkPosition();
            guiStyle.normal.textColor = UnityGUITools.ColorWithAlpha(guiStyle.normal.textColor, alpha);
            if (screenPos.z < 0)
            {
                return;
            }
            Rect rect = new Rect(screenPos.x - (size.x / 2), (Screen.height - screenPos.y) - (size.y / 2), size.x, size.y);

            UnityGUITools.DrawText(rect, message, guiStyle, textStyle, textStyleColor);
        }
Beispiel #5
0
        private void DrawSubstringLeftAligned()
        {
            var currText  = string.Empty;
            int start     = 0;
            int charsLeft = substringLength;

            while (charsLeft > 0)
            {
                string line    = GetNextLine(text, start);
                string subLine = line.Substring(0, Mathf.Min(line.Length, charsLeft));
                start     += line.Length;
                charsLeft -= line.Length;
                if (string.IsNullOrEmpty(currText))
                {
                    currText = subLine;
                }
                else
                {
                    currText += "\n" + subLine;
                }
            }
            UnityGUITools.DrawText(rect, GetRichTextClosedText(currText), GuiStyle, textStyle, textStyleColor);
        }