Author Topic: Scaling UI between resolutions  (Read 3865 times)

Narv

  • Guest
Scaling UI between resolutions
« on: July 22, 2013, 12:00:46 PM »
Hello,

I have created a UI  using the paid version of NGUI 2.5.1

The UI looks correct in the game window but when I build and put the APK file on the android device, it doesn't scale properly. Also when I "maximize on play" in Unity, the UI doesn't scale properly.

I have another Asset (Easy Touch 3) that does scale properly between the devices.

I have tried looking around the forums and tried changing the values of the height for manualHeight in both script and in the inspector for UIRoot.
I tried using the UIStretch script with NGUI and have been unable to get that to work.
I have also tried parenting the UI under another object and applying an anchor and stretch script on that to see if that would work as I read that in another thread.

Any help is appreciated.
Thank you.

LightSky

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 56
    • View Profile
Re: Scaling UI between resolutions
« Reply #1 on: July 22, 2013, 01:09:15 PM »
Check out the UI anchor example to see how to properly account for multiple resolutions.
I also am using Easy Touch 3 and it and NGUI both work fine together.

My UI Root setup is Fixed Size, Manual Height 720, Min 320, Max 1536. 
My application scales to any device fine and yours should too as long as you are anchoring your components appropriately.

If you need something to always be at the top, parent it to a Top Anchor.  Same thing goes for center, bottom ect. 
Quote
I have also tried parenting the UI under another object and applying an anchor and stretch script on that to see if that would work as I read that in another thread.
You shouldn't be parenting the UI Root itself if that is what you meant.  A basic setup would look something like this:

UI Root
  - Camera
     -Panel
        -Anchor Top  (Align with Top)
            -Offset
               -Progress Bar  (This will always be at the top)
        -Anchor Bottom (Align with Bottom)
            -Offset
               -Chat Window  (This will always be at the bottom)


If you need any more help feel free to ask.

Narv

  • Guest
Re: Scaling UI between resolutions
« Reply #2 on: July 22, 2013, 02:00:49 PM »
Thanks for the help LightSky!

I did try looking through the Examples, maybe I just missed something.  It works now after I set everything up using your example as a guide. I appreciate it very much! :D

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Scaling UI between resolutions
« Reply #3 on: July 22, 2013, 03:11:51 PM »
I'd like to ask for clarity: Do you want your UI to scale (stretch) or reposition (anchor/align)?

Something I quite like about both UIStretch and UIAnchor is that you can specify the panel or another UIWidget (like a UITexture, UISprite or UILabel) as the anchor reference point. That way, I have a small window that uses a UISprite as its background, and can put my "Close Window" button to be cemented against its top-right corner, regardless of the size of the entire window. It also means that my backgrounds can be stretched to exactly the size of that UIWidget if I don't want it to stretch across the entire UIPanel.