Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Use any font as a monospace font

Discussion in 'UGUI & TextMesh Pro' started by msklywenn, Sep 15, 2016.

  1. msklywenn

    msklywenn

    Joined:
    Nov 28, 2014
    Posts:
    67
    Hello !

    Did anyone found how to do it ? It would be nice for displaying scores and stuff like that.

    I couldn't find the option anywhere so I downloaded the UI source code from bitbucket but it seems what I need is buried inside UnityEngine.TextGenerator which seems to be on the native side.

    TextGenerator.characters has a UICharInfo structure which does have charWidth. That could be forced to the width of max(width(M), width(W), width('00')) (see definition of quadrats in typography). Unfortunately, I could find any setters for that :(

    Does anybody have another solution that doesn't involve using boring fonts or render quads manually ? :)
     
  2. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    If you are unable to find an acceptable solution, may I suggest you take a look at TextMesh Pro which is a replacement for Unity's text component like UI.Text but provides much improved functionality which includes over 30 rich text tags including the <mspace=x.xx> </mspace> tag where characters enclosed in the tag use monospace.

    Here is an example where the top text is using proportional spacing and bottom the <mspace> tag.



    The font that I used for this example is Anja Eliane Accent. The visual style of the text is done by using a Material Preset as TextMesh Pro provides the ability to dynamically style the text via material properties. See the following post where you can see the material properties on this text object.

    Below is an image of this same text object with default material settings.



    Now the same one with a Outline and Soft Shadow.

     
    Last edited: Sep 15, 2016
    Schnepperling and ZeroRare like this.