Auto adjust of fonts size.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
HaiiroMukuro
Posts: 80
Joined: Sun Jul 17, 2016 3:38 pm

Auto adjust of fonts size.

Post by HaiiroMukuro »

Good day! :D
It is possible that the font size of dialogues in every entry will automatically adjust? Like the shorter the dialogue the bigger the font size and the longer the dialogue the smaller the fontsize. Is there a way to do it? Please teach me. :D
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Auto adjust of fonts size.

Post by HawkX »

I actually just did that on my personal project so I thought i'd share ;)
Let me know if that was unwanted and I wont do that again if that is the case!

Here is how I did it :
In the Hierarchy, under your dialogue manager prefab, you should have a canvas which holds your UI selections (or the generic ones)

You should be able to find the "text panels" for any type of text window managed by the Dialogue Manager... in there, you have a simple text component which is managed by Unity...

you can there set the font, font size, word wrap or overflow... as well as use "Best Fit" which will auto scale the font based on available space... you then set the minimum font size and max size you want it to go to...
(be careful however if you have too long sentences and wrap/overflow enabled it will use the biggest font by default and go over the window)

I hope I was able to help a bit :)
Have a nice day!
User avatar
Tony Li
Posts: 21069
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto adjust of fonts size.

Post by Tony Li »

EDIT: Looks like HawkX beat me to it. His answer is spot-on.

(Was: If you're using Unity UI, inspect the Text component and tick Best Fit. You can experiment with it at design time to get the look you want. Just type text into the Text area. You may need to check other settings, like the maximum font size, the Rect Transform's size, etc.)
HaiiroMukuro
Posts: 80
Joined: Sun Jul 17, 2016 3:38 pm

Re: Auto adjust of fonts size.

Post by HaiiroMukuro »

Thanks for the help hawkx also tony :D
I forgot to tell about the ui prefab I'm using. I'm using the JRPG UI with continue button. I check again the prefab. I saw a section named "auto size." What the auto size does?
User avatar
Tony Li
Posts: 21069
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto adjust of fonts size.

Post by Tony Li »

Hi,

You're using the legacy Unity GUI system. Unfortunately it doesn't have a "Best Fit" option. Auto Size resizes the Scaled Rect to fit the contents, but it doesn't change the text size.

There's an equivalent Unity UI version of the JRPG UI in Prefabs / Unity UI Prefabs / JRPG. Can you use this instead?

To use it:

1. Remove the JRPG Dialogue UI from the scene if it's there.

2. Inspect the Dialogue Manager, and unassign the Dialogue UI field.

3. In the Hierarchy view, right-click on the Dialogue Manager and select Create > UI > Canvas.

4. Drag the JRPG Unity UI Dialogue UI prefab onto the Canvas so it becomes a child of the Canvas. The hierarchy should look like this:
  • Dialogue Manager
    • Canvas
      • JRPG Unity UI Dialogue UI
5. Expand JRPG Unity UI Dialogue UI, and inspect the Dialogue Panel. Set the Canvas Group's alpha value to 1 so you can see the text elements.

6. Inspect the text elements, tick Best Fit, and experiment with the settings in the editor to get the look you want.
Post Reply