Chat box and text scale

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
phatality123
Posts: 8
Joined: Tue Dec 23, 2014 9:22 am

Chat box and text scale

Post by phatality123 »

Hello. For my project I'm currently using the JRPG w/ continue button base. I've been trying to figure out how to make the entire thing (textbox panel, character portrait panel, and text itself) scale down accordingly with the resolution/size of the viewport window of the game, but haven't been successful in finding a way. I've tried messing with the settings in the GUI Root and its children, such as switching everything to be scaled on the Normalized function, but I couldn't quite find a way to get it to work. Any idea on how to get the whole thing to scale up/down with resolution? Thanks.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Chat box and text scale

Post by Tony Li »

Hi,



You can scale the panels by setting their scaled rects to Normalized, but unfortunately the legacy Unity GUI doesn't provide a way to scale fonts. The best you can do is to use a script to set the font size bigger or smaller compared to a default reference size. For example, if your font is size 20 at 1024x768, then set it to font size 10 at 512x384. Others have used the script in the recipe below to do this:



Recipe: Scale Font Size in Unity GUI



When setting scaled rects, be aware of the minimum set at the bottom of the scaled rect section. For example, if your resolution is 1024x768 and the width is set 0.5 normalized, it will be 512 pixels wide. But if you've set the minimum width to 700 pixels, it will always be at least 700 pixels wide, not 512.



Please feel free to post screenshots or send an example project to tony (at) pixelcrushers.com if you'd like me to take a closer look at anything.
phatality123
Posts: 8
Joined: Tue Dec 23, 2014 9:22 am

Chat box and text scale

Post by phatality123 »

Ok thanks. Do I set this to the GUI Root or do I have to manually edit all of it's children?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Chat box and text scale

Post by Tony Li »

Add ScaleFontSize to your GUI Root GameObject.



Then set the Styles list size to 5, and add these style names:

label

Response

Top Left

Middle Center

BottomCenter

You may need to tweak the Scale Factor, or even customize the script to your own specific needs.



If you're using Unity 4.6 or higher, consider using the new Unity UI, which makes scaling easier with its Canvas Scaler component. The Dialogue System's UI prefabs haven't been converted over to Unity UI yet because several developers are still on Unity 4.3, so you'd have to place the UI elements yourself.
phatality123
Posts: 8
Joined: Tue Dec 23, 2014 9:22 am

Chat box and text scale

Post by phatality123 »

Yeah I've thought about using it along with unity's new UI, since thats how I'm currently getting my other GUI parts to work the way I want, but wasn't sure exactly how to integrate the two together. So far I've gotten the Dialogue UI to shrink/expand along with resolution (somewhat) but it doesn't do it uniformly, as shown in the pictures below..



As opposed to this when the resolution is reduced:











How would I go about making the entire thing shrink/expand? Or would it only work if I use it with the new Unity UI? Sorry if this question seems vague.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Chat box and text scale

Post by Tony Li »

On the JRPG Dialogue UI, the scaled rect of "Dialogue Panel" is set to an absolute pixel height (128 pixels). Try changing this to Normalized at, say, 0.25 (one-quarter the screen height) or whatever proportion looks good to you. And then set Min Pixel Height to the smallest pixel height that you'll allow; this prevents the panel from scaling down so small that it's unreadable.



Do the same for any other UI elements that aren't scaling right.







On the other hand, if you want to use the new Unity UI, see the Unity UI Dialogue UI section for instructions.
phatality123
Posts: 8
Joined: Tue Dec 23, 2014 9:22 am

Chat box and text scale

Post by phatality123 »

Ok I'll give that a try, or will otherwise look into using unity UI. Thanks for the help
Post Reply