Get size/position of a panel?

Is there a way to get the size/position of a panel of GUI?

anchoredPosition and sizeDelta should do it

^ That, or RectTransform.rect.

Is there a way to get the screen space position? As RectTransform.rect is local(I want to use rect.contains with the mouse on it).

You can use http://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html on the position of the RectTransform (not anchoredPosition) or one of the corners (there are methods on RectTransform to get the corners).

We can’t provide the whole rect combined in screen space since it may be rotated, so it may not make sense.

That’s true, but what about providing stuff to get the ‘bounds’ rather than the rect? Same as is done for any other renderer. For non-rotated objects it should be the same as the rect, and for rotated objects it would still be doing something useful.

Yes, none of my UI is rotated so something like that would be useful.

1 Like