Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
11
Question by moghes · Jan 21, 2013 at 11:43 AM · fontsize

Dynamically Setting font size according to device Screen dpi

Hello everyone!

I am facing a problem with the font size for mobile devices. I am testing on a device with 200 dpi(font size normal) and on a device with 300+ dpi, where the text appears too small.

Since there are too many devices each with a different dpi .. Do I have to have 10-20 instances of the same font(which doesn't sound to be the optimal solution).

Any hints?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Apr 05, 2016 at 12:15 PM 0
Share

Note

Fortunately these days (2016+) Unity has ordinary dynamic type (type with sizes!) built-in. There is nothing to do.

Just drop in a .ttf file and away you go.

However... Unity also today offers sprite sheet fonts, which is great. But, you must put in your project the awesome BitmapFontImporter by Benoit Freslon. Unity have not yet included a system for mapping the data on a custom font, BitmapFontImporter does it perfectly. It's a "must have".

So that's all there is to it these days.

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Fattie · Feb 19, 2013 at 01:44 PM

Note!

Fortunately these days (2016+) Unity has ordinary dynamic type (type with sizes!) built-in. There is nothing to do.

Just drop in a .ttf file and away you go.

However often with games you want to use fancy type with glows, etc. To do this you just click the Unity menu item "Create Custom Font" and then you use something like GlyphDesigner to make your font.

For custom (sprite sheet) fonts, there is a critical tip...

You must put in your project the awesome BitmapFontImporter by Benoit Freslon. Unity have not yet included a system for mapping a custom font, BitmapFontImporter does it perfectly. It's a "must have".

https://github.com/BenoitFreslon/BitmapFontImporter

So that's all there is to it these days.


The old answers are of historic interest only, fortunately you can ignore all this...

Life used to be this hard!


Step one ... buy something like GlyphDesigner. Do anything you want with typography. Red glows, whatever. Choose a full ASCII set or just a limited set. (For example if it is for a Score, you only need 0123456789.) That will make the sprite sheet smaller.

alt text

Click the export button on GlyphDesigner. Drop the two files in to your Unity project. Click "make new 2DTK font."

Step two ... just get TK2D from the asset store (if you don't already). As well as being the 2D solution, it has a full typography solution thrown in as a bonus. Click to create a new font. Now just USE THAT IN YOUR PROJECT, just like any 3D object.

Never again think about screen resolution when doing text in a game. You can SEE exactly what you're doing and just move it around like any thing else in the scene. (Use an ortho camera for it if relevant.) It has NO connection to the damned "gui" systems.

Regarding the "resolution independent" type in Unity. It does not exist. I suspect they mean it's "resolution independent" if you do all the programming to make it work resolution independently.

Glyph designer: http://www.71squared.com/en/glyphdesigner or any similar product. 2DToolkit or another 3D text asset - asset store. Hope it helps

[2]: /storage/temp/8035-results.jpg

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
5

Answer by jamiahuswalton · Apr 05, 2016 at 02:35 AM

For something simple, I just changed a setting on my Canvas.

In the Canvas Scaler (Script) section, Change the UI Scale Mode to "Scale With Screen Size". That seemed to work for the simple game I am working on.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparkhou · Jun 12, 2016 at 07:05 AM 0
Share

@jamiahuswalton Thanks for your answer , that solved my problem!

avatar image Fattie · Jun 12, 2016 at 12:46 PM 0
Share

Note that these days, 2016, this answer is completely correct.

EVERYTHING on this page is only of historic interest. It is (finally) totally trivial to actually use type in Unity.

avatar image
2

Answer by robhuhn · Feb 14, 2013 at 09:49 AM

Dynamic fonts for mobile should be supported since Unity 4.0 but I've not tried it yet.

If you need another solution you could import the same non-dynamic font with different sizes for each resolution type and use a script to change the font on the fly. The class *DisplayMetricsUtil* provides GetResolutionType().

@edit: There are 4 types, so you should import your font 4 times. Let's say you want the font size set to 12dp, then import your fonts with size

  • 9 px (scale 0.75 - ldpi)

  • 12 px (scale 1 - mdpi)

  • 18 px (scale 1.5 - hdpi)

  • 24 px (scale 2 - xhdpi)

Set a switch on GetResolutionType() and assign the desired font.

The scales are described here: http://developer.android.com/guide/practices/screens_support.html alt text

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robhuhn · Feb 19, 2013 at 12:38 PM 0
Share

Why don't you switch the font with the desired font size regarding what GetResolutionType() returns?

Just to be clear, if you don't use Unity 4 or later, you need to import the same font for every size. GetResolutionType() only helps to decide which font should be taken.

avatar image robhuhn · Feb 21, 2013 at 08:45 AM 0
Share

Actually you only check for the resolution type, not the resolution itself.

 public class FontTest : $$anonymous$$onoBehaviour
 {
     //contains four fonts as described above - from ldpi [0] to xhdpi [3]
     public List<Font> fonts = new List<Font>();

     void Start () 
     {
         //get the font for the resolution type
         Font desiredFont = fonts[(int)Display$$anonymous$$etricsUtil.GetResolutionType()]; 
         myLabelStyle = myLabelStyle.DpToPixel(); //e.g. to adjust bounds
         myLabelStyle.font = desiredFont;
     }
 }

That should be all you need.

avatar image robhuhn · Jul 19, 2013 at 11:06 AM 0
Share

Yes, but keep in $$anonymous$$d that this is deprecated since Unity 4 supports dynamic fonts on mobile.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simple way to change GUIText font size 4 Answers

Subscripts and superscripts in Unity new GUI 2 Answers

how to re-scale guiStyle property as per screen resolution? 1 Answer

Photoshop font size VS Unity font size 2 Answers

How to get the current "best fit" size of a Text component? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges