Author Topic: Widget size / .border / .relativeSize, OrthSize and world coords  (Read 9869 times)

phildo77

  • Guest
I'd like to retrieve the size of widgets (Buttons, labels, etc.) in world coordinates.  I see the properties .border and .relativeSize contained in UISprite but I'm not exactly sure what these properties represent.

Almost every widget on my panel is moved around for animation effects at some point and my platform targets include many different screen resolutions.  The entire panel is scaled depending on aspect ratio/screen height.  I need the widget size in world coords so I can place them correctly on the screen based on viewable screen in world coordinates.

I am not using a camera with an OSize of 1 and doing so is not feasible at this point.  Is there still an avenue that I can take that will allow me to get widget size in world coords?

Additionally, I'm seeing a lot of talk about making sure the OSize is 1 on other posts.  Is there a technical, in depth explanation as to why this is suggested?

Thanks in advance for the support!

ranilian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
    • Industry Corporation
Re: Widget size / .border / .relativeSize, OrthSize and world coords
« Reply #1 on: June 27, 2012, 08:00:57 PM »
Look at NGUIMath.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Widget size / .border / .relativeSize, OrthSize and world coords
« Reply #2 on: June 27, 2012, 08:55:01 PM »
NGUIMath.CalculateAbsoluteWidgetBounds to be precise.

Technical in-depth explanation? No. Size of 1 just makes the size of your UI small and manageable. By default if your characters are say, 2 meters tall (2 units), and your UI is in pixel coordinates, and you're on a 1920x1080 resolution, that means your UI is 500 times taller than your in-game model. Just makes managing it a pain. Size 1 keeps it small.

phildo77

  • Guest
Re: Widget size / .border / .relativeSize, OrthSize and world coords
« Reply #3 on: June 28, 2012, 09:03:37 AM »
Thank you, I appreciate the support.

Regarding orthosize, I was getting the impression that some components of NGUI break if it is set to 1 after reading some of the other support posts in the forum.  I'm glad this is not the case.

For my edification and to close up the topic, what do .border and .relativeSize on the UISprite properties represent and what units are they in?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Widget size / .border / .relativeSize, OrthSize and world coords
« Reply #4 on: June 28, 2012, 10:54:45 AM »
You can create UIs without UIRoot if you like. 3D UIs don't need UIRoot, for example. There was something that liked having ortho camera size of 1, but I don't recall what it was...

UISprite.border is the border size for sliced sprites. UIWidget.relativeSize is the size of the widget. Both are in relative coordinates. You can get pixel size by scaling the value by transform.localScale. You can get world size by scaling it by transform.lossyScale (not recommended due to how Unity handles scaling).