1
NGUI 3 Support / Re: Size of UISprite after UIRoot Scaling?
« on: August 22, 2013, 11:45:54 AM »
First off, thank you very much for the support. I've been struggling to find an answer to this for quite some time now and no one else who's used NGUI seems to have run across the same need as I.
Thank you! If I take my UISprite's size (125px) and divide it by UIRoot.GetPixelSizeAdjustment(MyUISprite.gameObject), I get 86 - which happens to be the size on screen which is exactly what I wanted!
This is correct. However, I am targeting devices in a landscape ratio, and didn't want wide bars on the edge of the screen (which would have been the result of laying out my levels in the most square aspect ratio there was and just leaving it up to NGUI's scaling to squash it down to fit.)
Thanks!
Edit:
Just an example of what it lets me do:


Same code automatically positions all of the icons in both examples and the UIRoot.GetPixelSizeAdjustment function was required to figure out how many of the icons I could fit given Screen.Width.
UIRoot.pixelSizeAdjustment is what you're looking for. You need to take it into account.
Thank you! If I take my UISprite's size (125px) and divide it by UIRoot.GetPixelSizeAdjustment(MyUISprite.gameObject), I get 86 - which happens to be the size on screen which is exactly what I wanted!
Quote
However... not sure why you'd want to to be honest. Fixed size means your UI will always be treated as that dimension. So for example if it's 800, that means the height from NGUI's point of view will always remain 800 pixels, regardless of screen resolution. This makes it really easy to position your stuff as Screen.height is irrelevant.
This is correct. However, I am targeting devices in a landscape ratio, and didn't want wide bars on the edge of the screen (which would have been the result of laying out my levels in the most square aspect ratio there was and just leaving it up to NGUI's scaling to squash it down to fit.)
Thanks!
Edit:
Just an example of what it lets me do:


Same code automatically positions all of the icons in both examples and the UIRoot.GetPixelSizeAdjustment function was required to figure out how many of the icons I could fit given Screen.Width.
