Page 1 of 1

Auto adjust of fonts size.

Posted: Tue Feb 28, 2017 9:37 am
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

Re: Auto adjust of fonts size.

Posted: Tue Feb 28, 2017 10:29 am
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!

Re: Auto adjust of fonts size.

Posted: Tue Feb 28, 2017 10:39 am
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.)

Re: Auto adjust of fonts size.

Posted: Tue Feb 28, 2017 11:06 am
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?

Re: Auto adjust of fonts size.

Posted: Tue Feb 28, 2017 11:36 am
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.