Author Topic: UIRoot behavior with orientation changes  (Read 10130 times)

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
UIRoot behavior with orientation changes
« on: March 09, 2017, 11:51:48 AM »
We plan on supporting all aspect ratios and orientations for our project.  We've gotten the basics down on how to use all the NGUI stuff, but what we were curious about was how the UIRoot deals with orientation changes.  For example, right now our UIRoot is set to 1024x768, Contrained, and both "Fit" buttons are unchecked.  So if we're working on a screen that's at that size, positioning a UISprite at 0,-768 will position the sprite at the bottom of the screen with the bottom half cut off (pivot is all centered).  That makes sense since the screen height is 768.  However, when we switch to Portrait mode, the screen size is now 1024, but to get the sprite positioned at the bottom, you don't set the Y to -1024, you still set it to -768.  I'm sure there's lots of behind the scenes that explains this but it's a bit confusing for laying stuff out, especially with our less technical staff members who want to set up things at the bottom of a Portrait screen but the numbers don't make sense in the current orientation.
What we were thinking of doing is (both at edit time and run time) if an orientation change is detected, we'd update those numbers accordingly.  So in landscape it's 1024x768 and in portrait it's 768x1024, so the layout positions would make more since.
However, since we're still not 100% sure how the UIRoot works behind the scenes, we were wondering if doing this is a horrible idea, a great idea, and what the reasons would be either way.  We're going ahead with testing this but please let us know if there's any reason why this would be bad.
Thank you!! 
-Mo

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIRoot behavior with orientation changes
« Reply #1 on: March 10, 2017, 11:47:51 AM »
Orientation change happens in a way that's invisible to the user. The width and height get flipped, but that's it. There is nothing that needs to be done. If you had something anchored to the bottom left corner, it will still be anchored to the bottom left corner if the orientation changes because as far as the application knows, the only thing that changed were the width and height of the screen. That said, since in your case the UIRoot has a fixed size, you will run into a situation where it won't match the screen's aspect ratio anymore... so you can indeed simply check for this manually -- in the custom script's Update() function check Screen.width and Screen.height, and adjust the UIRoot's size accordingly.

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: UIRoot behavior with orientation changes
« Reply #2 on: March 23, 2017, 09:45:29 AM »
Excellent, we've been moving forward.
Thanks!
-Mo