Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Shifty Geezer on December 28, 2016, 04:22:53 PM
-
Given screen coordinates from (0,0) to (1,1), how does one set the position of a widget? In the editor I can set transform's position to +/- UI dimensions/2, but setting widget.transform.position or localPosition either set the transform a tiny amount or a huge amount.
-
Note the intention is to use the widget's pivot, so two sprites set to position (0.25,0.25) only with one's widget set Left aligned and the other's Right aligned would both be positioned side-by-side at (240,135) in UI space in a 1920x1080 UI.
-
take a look at:
NGUITools.FitOnScreen
-
This isn't actually an NGUI question, but a Unity / math question. You need to use math to convert from one transform's space to another. Look at NGUITools.OverlayPosition for an example.
-
I replied to this but it hasn't appeared. NGUITools.FitOnScreen didn't work because it clamps to the borders (designed for tooltips) but it showed that NGUI just uses localPosition, leading me to investigate the values I was passing.
Turns out you can just set the transform.localPosition to NGUI screen coordinates and it works. It's simple enough to get the UI dimensions and multiply by whatever screen coordinate system you want to use, whether 0 to 1 or -0.5 to 0.5 or whatever.