File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,28 @@ namespace Zigurous.UI
77 /// </summary>
88 public static class RectTransformExtensions
99 {
10+ private static Vector3 [ ] corners = new Vector3 [ 4 ] ;
11+
12+ /// <summary>
13+ /// Calculates the world-space rect of the transform.
14+ /// <summary>
15+ /// <param name="transform">The transform to calculate the world rect of.</param>
16+ /// <param name="ignoreScale">Ignores the scale of the transform when setting the rect size (default=false).</param>
17+ /// <returns>The world rect of the transform.</returns>
18+ public static Rect GetWorldRect ( this RectTransform transform , bool ignoreScale = false )
19+ {
20+ transform . GetWorldCorners ( corners ) ;
21+
22+ Vector3 topLeft = corners [ 0 ] ;
23+ Vector3 size = transform . rect . size ;
24+
25+ if ( ! ignoreScale ) {
26+ size . Scale ( transform . lossyScale ) ;
27+ }
28+
29+ return new Rect ( topLeft , size ) ;
30+ }
31+
1032 /// <summary>
1133 /// Sets the width of the rect transform to the given value.
1234 /// </summary>
You can’t perform that action at this time.
0 commit comments