public void SetFontStyle(TMPro.FontStyles style)
 {
     if (text == null)
     {
         return;
     }
     text.fontStyle = style;
 }
Example #2
0
 /// <summary>
 /// Sets the font style.
 /// </summary>
 /// <param name="useStyle">The text font style to use</param>
 public void SetFontStyle(FontStyle useStyle)
 {
     CloneStyle = false;
     Style      = useStyle;
     if (TextObject != null)
     {
         TextText.fontStyle = Style;
         DoAlignment();
     }
 }
 public void CloneFromTextMeshPro(TMPro.TextMeshProUGUI text)
 {
     this.font = text.font;
     this.fontSharedMaterial = text.fontSharedMaterial;
     this.fontStyle          = text.fontStyle;
     this.color              = text.color;
     this.colorGradient      = text.colorGradient;
     this.fontSize           = text.fontSize;
     this.alignment          = text.alignment;
     this.enableWordWrapping = text.enableWordWrapping;
     this.overflowMode       = text.overflowMode;
 }
Example #4
0
    IEnumerator DisplayTitleForTime(string message, float seconds, Color col, TMPro.FontStyles style)
    {
        string before    = titleText.text;
        Color  colBefore = titleText.color;

        TMPro.FontStyles styBefore = titleText.fontStyle;

        titleText.text      = message;
        titleText.color     = col;
        titleText.fontStyle = style;
        yield return(new WaitForSeconds(seconds));

        titleText.text      = before;
        titleText.color     = colBefore;
        titleText.fontStyle = styBefore;
    }
Example #5
0
 static FontStyle TMPFontStyleToFontStyle(TMPro.FontStyles tmpStyle)
 {
     if (tmpStyle == TMPro.FontStyles.Bold)
     {
         return(FontStyle.Bold);
     }
     else if (tmpStyle == (TMPro.FontStyles.Bold | TMPro.FontStyles.Italic))
     {
         return(FontStyle.BoldAndItalic);
     }
     else if (tmpStyle == TMPro.FontStyles.Italic)
     {
         return(FontStyle.Italic);
     }
     return(FontStyle.Normal);
 }
        private GameObject CreateLabel(
            int id,
            string text,
            string fontName,
            float fontSize,
            TMPro.FontStyles fontStyle,
            TMPro.TextAlignmentOptions alignment,
            Transform labelTransform,
            Vector3 labelPositionOffset,
            Quaternion labelRotationOffset,
            Vector2 rectPivot,
            Vector2 rectSize)
        {
            string labelName = internalProp.name + "-" + internalProp.propID + "-" + id;

            GameObject labelGameObject = new GameObject(labelName);

            labelGameObject.layer = 20;
            labelGameObject.transform.SetParent(labelTransform);

            TMPro.TextMeshPro tmpLabel = labelGameObject.AddComponent <TMPro.TextMeshPro>();
            tmpLabel.SetText(text);
            tmpLabel.fontSize  = fontSize;
            tmpLabel.fontStyle = fontStyle;
            tmpLabel.alignment = alignment;

            tmpLabel.rectTransform.pivot         = rectPivot;
            tmpLabel.rectTransform.localPosition = labelPositionOffset;
            tmpLabel.rectTransform.localRotation = labelRotationOffset;
            tmpLabel.rectTransform.sizeDelta     = rectSize;

            // find and set font
            TMPro.TMP_FontAsset tmpFont = AssetLoader.Instance.GetFont(fontName);
            if (tmpFont != null)
            {
                tmpLabel.font = tmpFont;
            }
            else
            {
                Utils.LogWarning("KVR_DigitalIndicator font not found!");
            }

            return(labelGameObject);
        }
        private void CreateLabels()
        {
            // font style (bold, italics, etc)
            TMPro.FontStyles labelDisplayFontStyle = TMPro.FontStyles.Normal;
            bool             success = moduleConfigNode.TryGetEnum("labelDisplayFontStyle",
                                                                   ref labelDisplayFontStyle, TMPro.FontStyles.Normal);

            // label
            GameObject labelTextGameObject = CreateLabel(
                0, labelDisplayText, labelDisplayFont, labelDisplayFontSize, labelDisplayFontStyle,
                TMPro.TextAlignmentOptions.TopLeft, labelDisplayGameObject.transform,
                labelDisplayOffset, Quaternion.identity, labelDisplayPivot, labelDisplaySize);

            labelDisplayTextLabel = labelDisplayGameObject.GetComponent <TMPro.TextMeshPro>();

            // digit display
            GameObject displayTextGameObject = CreateLabel(
                1, "0.0", digitDisplayFont, digitDisplayFontSize, TMPro.FontStyles.Normal,
                TMPro.TextAlignmentOptions.TopLeft, digitDisplayGameObject.transform,
                digitDisplayOffset, Quaternion.identity, digitDisplayPivot, digitDisplaySize);

            digitDisplayTextLabel = displayTextGameObject.GetComponent <TMPro.TextMeshPro>();
        }
Example #8
0
        protected GameObject CreateLabel(
            string gameObjectName,
            string text,
            TMPro.TMP_FontAsset font,
            float fontSize,
            TMPro.FontStyles fontStyle,
            TMPro.TextAlignmentOptions textAlignment,
            Transform parentTransform,
            Vector3 positionOffset,
            Quaternion rotationOffset,
            Vector2 rectPivot,
            Vector2 rectSize)
        {
            GameObject labelGameObject = new GameObject(gameObjectName);

            labelGameObject.layer = 20;
            labelGameObject.transform.SetParent(parentTransform);

            TMPro.TextMeshPro tmpLabel = labelGameObject.AddComponent <TMPro.TextMeshPro>();
            tmpLabel.SetText(text);
            tmpLabel.fontSize  = fontSize;
            tmpLabel.fontStyle = fontStyle;
            tmpLabel.alignment = textAlignment;

            tmpLabel.rectTransform.pivot         = rectPivot;
            tmpLabel.rectTransform.localPosition = positionOffset;
            tmpLabel.rectTransform.localRotation = rotationOffset;
            tmpLabel.rectTransform.sizeDelta     = rectSize;

            // find and set font
            if (font != null)
            {
                tmpLabel.font = font;
            }

            return(labelGameObject);
        }
        private GameObject CreateLabel(
            string name,
            string text,
            float fontSize,
            Vector3 offset,
            TMPro.FontStyles fontStyle = TMPro.FontStyles.Normal)
        {
            GameObject labelGameObject = new GameObject(internalProp.name + " " + name);

            labelGameObject.layer = 20;
            labelGameObject.transform.SetParent(internalProp.transform);

            TMPro.TextMeshPro tmpLabel = labelGameObject.AddComponent <TMPro.TextMeshPro>();
            tmpLabel.SetText(text);
            tmpLabel.fontSize  = fontSize;
            tmpLabel.alignment = TMPro.TextAlignmentOptions.Center;
            tmpLabel.fontStyle = fontStyle;

            tmpLabel.rectTransform.localPosition = offset;
            tmpLabel.rectTransform.localRotation = Quaternion.Euler(90f, 0f, 180f);
            tmpLabel.rectTransform.sizeDelta     = new Vector2(0.2f, 0.2f);

            return(labelGameObject);
        }
Example #10
0
        public KVR_Label(InternalProp prop, ConfigNode configuration)
        {
            // label text
            string text    = "";
            bool   success = configuration.TryGetValue("text", ref text);

            if (success)
            {
                Text = text;
            }

            // label transform (where to place the label)
            ParentTransform = ConfigUtils.GetTransform(prop, configuration, "parentTransformName");

            // position offset from the transform
            Vector3 positionOffset = Vector3.zero;

            success = configuration.TryGetValue("positionOffset", ref positionOffset);
            if (success)
            {
                PositionOffset = positionOffset;
            }

            // rotation offset from the transform
            Quaternion rotationOffset = Quaternion.identity;

            success = configuration.TryGetValue("rotationOffset", ref rotationOffset);
            if (success)
            {
                RotationOffset = rotationOffset;
            }

            // font
            string fontName = "";

            success = configuration.TryGetValue("fontName", ref fontName);
            if (success)
            {
                Font = AssetLoader.Instance.GetFont(fontName);
                if (Font == null)
                {
                    Utils.LogWarning("KVR_Label: font \"" + fontName + "\" not found!");
                }
            }

            // font size
            float fontSize = 0.1f;

            success = configuration.TryGetValue("fontSize", ref fontSize);
            if (success)
            {
                FontSize = fontSize;
            }

            // font style (bold, italics, etc)
            TMPro.FontStyles fontStyle = TMPro.FontStyles.Normal;
            success = configuration.TryGetEnum("fontStyle", ref fontStyle, TMPro.FontStyles.Normal);
            if (success)
            {
                FontStyle = fontStyle;
            }

            // font alignment
            TMPro.TextAlignmentOptions textAlignment = TMPro.TextAlignmentOptions.Center;
            success = configuration.TryGetEnum("textAlignment", ref textAlignment, TMPro.TextAlignmentOptions.Center);
            if (success)
            {
                TextAlignment = textAlignment;
            }

            // canvas pivot (anchor point on the canvas)
            Vector2 rectPivot = new Vector2(0.5f, 0.5f);

            success = configuration.TryGetValue("rectPivot", ref rectPivot);
            if (success)
            {
                RectPivot = rectPivot;
            }

            // size of the label canvas
            Vector2 rectSize = new Vector2(0.2f, 0.2f);

            success = configuration.TryGetValue("rectSize", ref rectSize);
            if (success)
            {
                RectSize = rectSize;
            }

            // create the label
            string gameObjectName = prop.name + "-" + prop.propID + "-" + configuration.id;

            LabelGameObject = CreateLabel(
                gameObjectName,
                Text,
                Font,
                FontSize,
                FontStyle,
                TextAlignment,
                ParentTransform,
                PositionOffset,
                RotationOffset,
                RectPivot,
                RectSize);
        }