UnityEssentials
Small but useful tools and features for Unity
RectTransformExtensions.cs
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 Copyright (c) 2015 Christian 'ketura' McCarty
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 
26 // Thanks Christian 'ketura' McCarty for your code, which I found extremely useful and a must-have.
27 
28 
29 namespace UnityEngine
30 {
31 
35  public static class RectTransformExtensions
36  {
42  public static Rect GetWorldRect(this RectTransform rt)
43  {
44  // Be aware: a standard Rect has the position as the upper-left corner,
45  // and I think the Unity UI stuff somehow repurposes this to instead point to the
46  // lower-left. I'm not 100% sure on this, but I've had some unexplained wierdnesses.
47  Vector3[] corners = new Vector3[4];
48  rt.GetWorldCorners(corners);
49  Vector2 size = new Vector2(corners[2].x - corners[1].x, corners[1].y - corners[0].y);
50  return new Rect(new Vector2(corners[1].x, -corners[1].y), size);
51  }
52 
57  public static MinMax01 GetAnchors(this RectTransform rt)
58  {
59  return new MinMax01(rt.anchorMin, rt.anchorMax);
60  }
61 
62 
66  public static void SetAnchors(this RectTransform rt, MinMax01 anchors)
67  {
68  rt.anchorMin = anchors.min;
69  rt.anchorMax = anchors.max;
70  }
71 
76  public static RectTransform GetParent(this RectTransform rt)
77  {
78  return rt.parent as RectTransform;
79  }
80 
85  public static float GetWidth(this RectTransform rt)
86  {
87  return rt.rect.width;
88  }
89 
94  public static float GetHeight(this RectTransform rt)
95  {
96  return rt.rect.height;
97  }
98 
103  public static Vector2 GetSize(this RectTransform rt)
104  {
105  return new Vector2(rt.GetWidth(), rt.GetHeight());
106  }
107 
111  public static void SetWidth(this RectTransform rt, float width)
112  {
113  rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
114  }
115 
119  public static void SetHeight(this RectTransform rt, float height)
120  {
121  rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
122  }
123 
129  public static void SetSize(this RectTransform rt, float width, float height)
130  {
131  rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
132  rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
133  }
134 
139  public static void SetSize(this RectTransform rt, Vector2 size)
140  {
141  rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
142  rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
143  }
144 
149  public static Vector2 GetLeft(this RectTransform rt)
150  {
151  return new Vector2(rt.offsetMin.x, rt.anchoredPosition.y);
152  }
153 
158  public static Vector2 GetRight(this RectTransform rt)
159  {
160  return new Vector2(rt.offsetMax.x, rt.anchoredPosition.y);
161  }
162 
167  public static Vector2 GetTop(this RectTransform rt)
168  {
169  return new Vector2(rt.anchoredPosition.x, rt.offsetMax.y);
170  }
171 
176  public static Vector2 GetBottom(this RectTransform rt)
177  {
178  return new Vector2(rt.anchoredPosition.x, rt.offsetMin.y);
179  }
180 
181 
182  // Set[edgeName](float) is similar to setting the "Left" etc variables in the inspector. Unlike the inspector, these
183  // can be used regardless of anchor position. Be warned, there's a reason the functionality
184  // is hidden in the editor, as the behavior is unintuitive when adjusting the parent's rect.
185  // If you're calling these every frame or otherwise updating frequently, shouldn't be a problem, though.
186  //
187  //Keep in mind that these functions all use standard directions when determining positioning; this means
188  // that unlike the inspector, positive ALWAYS means to the right/top, and negative ALWAYS means to the left/
189  // bottom. If you want true inspector functionality, use Left() and so on, below.
190  //
191  //E.g., SetLeftEdge(-10) will turn
192  /*
193  .__________.
194  | |
195  | |
196  | [ ] |
197  | |
198  |__________|
199 
200  into
201  .__________.
202  | |
203  | |
204  [ ] |
205  | |
206  |__________|
207 
208  [ ] is the RectTransform, the bigger square is the parent
209  */
214  public static void SetLeft(this RectTransform rt, float distance)
215  {
216  float xmin = rt.GetParent().rect.xMin;
217  float anchorFactor = rt.anchorMin.x * 2 - 1;
218 
219  rt.offsetMin = new Vector2(xmin + (xmin * anchorFactor) + distance, rt.offsetMin.y);
220  }
225  public static void SetRight(this RectTransform rt, float distance)
226  {
227  float xmax = rt.GetParent().rect.xMax;
228  float anchorFactor = rt.anchorMax.x * 2 - 1;
229 
230  rt.offsetMax = new Vector2(xmax - (xmax * anchorFactor) + distance, rt.offsetMax.y);
231  }
236  public static void SetTop(this RectTransform rt, float top)
237  {
238  float ymax = rt.GetParent().rect.yMax;
239  float anchorFactor = rt.anchorMax.y * 2 - 1;
240 
241  rt.offsetMax = new Vector2(rt.offsetMax.x, ymax - (ymax * anchorFactor) + top);
242  }
247  public static void SetBottom(this RectTransform rt, float distance)
248  {
249  float ymin = rt.GetParent().rect.yMin;
250  float anchorFactor = rt.anchorMin.y * 2 - 1;
251 
252  rt.offsetMin = new Vector2(rt.offsetMin.x, ymin + (ymin * anchorFactor) + distance);
253  }
254 
255  // Truly matches the functionality of the "Left" etc property in the inspector. This means that
256  // Right(10) will actually move the right edge to 10 units from the LEFT of the parent's right edge.
257  // In other words, all coordinates are "inside": they measure distance from the parent's edge to the inside of the parent.
262  public static void Left(this RectTransform rt, float distance)
263  {
264  rt.SetLeft(distance);
265  }
270  public static void Right(this RectTransform rt, float distance)
271  {
272  rt.SetRight(-distance);
273  }
278  public static void Top(this RectTransform rt, float distance)
279  {
280  rt.SetTop(-distance);
281  }
286  public static void Bottom(this RectTransform rt, float distance)
287  {
288  rt.SetRight(distance);
289  }
290 
291 
297  public static void SetLeftFrom(this RectTransform rt, MinMax01 anchor, float distance)
298  {
299  Vector2 origin = rt.AnchorToParentSpace(anchor.min - rt.anchorMin);
300 
301  rt.offsetMin = new Vector2(origin.x + distance, rt.offsetMin.y);
302  }
308  public static void SetRightFrom(this RectTransform rt, MinMax01 anchor, float distance)
309  {
310  Vector2 origin = rt.AnchorToParentSpace(anchor.max - rt.anchorMax);
311 
312  rt.offsetMax = new Vector2(origin.x + distance, rt.offsetMax.y);
313  }
319  public static void SetTopFrom(this RectTransform rt, MinMax01 anchor, float distance)
320  {
321  Vector2 origin = rt.AnchorToParentSpace(anchor.max - rt.anchorMax);
322 
323  rt.offsetMax = new Vector2(rt.offsetMax.x, origin.y + distance);
324  }
330  public static void SetBottomFrom(this RectTransform rt, MinMax01 anchor, float distance)
331  {
332  Vector2 origin = rt.AnchorToParentSpace(anchor.min - rt.anchorMin);
333 
334  rt.offsetMin = new Vector2(rt.offsetMin.x, origin.y + distance);
335  }
336 
337 
338 
345  public static void SetRelativeLeft(this RectTransform rt, float distance)
346  {
347  rt.offsetMin = new Vector2(rt.anchoredPosition.x + distance, rt.offsetMin.y);
348  }
355  public static void SetRelativeRight(this RectTransform rt, float distance)
356  {
357  rt.offsetMax = new Vector2(rt.anchoredPosition.x + distance, rt.offsetMax.y);
358  }
365  public static void SetRelativeTop(this RectTransform rt, float distance)
366  {
367  rt.offsetMax = new Vector2(rt.offsetMax.x, rt.anchoredPosition.y + distance);
368  }
375  public static void SetRelativeBottom(this RectTransform rt, float distance)
376  {
377  rt.offsetMin = new Vector2(rt.offsetMin.x, rt.anchoredPosition.y + distance);
378  }
379 
380 
381 
382  //E.g., MoveLeft(0) will look like this:
383  /*
384  .__________.
385  | |
386  | |
387  [|] |
388  | |
389  |__________|
390  */
395  public static void MoveLeft(this RectTransform rt, float left = 0)
396  {
397  float xmin = rt.GetParent().rect.xMin;
398  float center = rt.anchorMax.x - rt.anchorMin.x;
399  float anchorFactor = rt.anchorMax.x * 2 - 1;
400  rt.anchoredPosition = new Vector2(xmin + (xmin * anchorFactor) + left - (center * xmin), rt.anchoredPosition.y);
401  }
406  public static void MoveRight(this RectTransform rt, float right = 0)
407  {
408  float xmax = rt.GetParent().rect.xMax;
409  float center = rt.anchorMax.x - rt.anchorMin.x;
410  float anchorFactor = rt.anchorMax.x * 2 - 1;
411  rt.anchoredPosition = new Vector2(xmax - (xmax * anchorFactor) - right + (center * xmax), rt.anchoredPosition.y);
412  }
417  public static void MoveTop(this RectTransform rt, float top = 0)
418  {
419  float ymax = rt.GetParent().rect.yMax;
420  float center = rt.anchorMax.y - rt.anchorMin.y;
421  float anchorFactor = rt.anchorMax.y * 2 - 1;
422  rt.anchoredPosition = new Vector2(rt.anchoredPosition.x, ymax - (ymax * anchorFactor) - top + (center * ymax));
423  }
428  public static void MoveBottom(this RectTransform rt, float bottom = 0)
429  {
430  float ymin = rt.GetParent().rect.yMin;
431  float center = rt.anchorMax.y - rt.anchorMin.y;
432  float anchorFactor = rt.anchorMax.y * 2 - 1;
433  rt.anchoredPosition = new Vector2(rt.anchoredPosition.x, ymin + (ymin * anchorFactor) + bottom - (center * ymin));
434  }
435 
436 
437 
438  //Moves the RectTransform to align the child left edge with the parent left edge, etc.
439  //E.g., MoveLeftInside(0) will look like this:
440  /*
441  .__________.
442  | |
443  | |
444  [ ] |
445  | |
446  |__________|
447  */
452  public static void MoveLeftInside(this RectTransform rt, float distance = 0)
453  {
454  rt.MoveLeft(distance + rt.GetWidth() / 2);
455  }
460  public static void MoveRightInside(this RectTransform rt, float distance = 0)
461  {
462  rt.MoveRight(distance + rt.GetWidth() / 2);
463  }
468  public static void MoveTopInside(this RectTransform rt, float distance = 0)
469  {
470  rt.MoveTop(distance + rt.GetHeight() / 2);
471  }
476  public static void MoveBottomInside(this RectTransform rt, float distance = 0)
477  {
478  rt.MoveBottom(distance + rt.GetHeight() / 2);
479  }
480 
481 
482  //Moves the RectTransform to align the child right edge with the parent left edge, etc
483  //E.g., MoveLeftOutside(0) will look like this:
484  /*
485  .__________.
486  | |
487  | |
488  [ ] |
489  | |
490  |__________|
491  */
497  public static void MoveLeftOutside(this RectTransform rt, float distance = 0)
498  {
499  rt.MoveLeft(distance - rt.GetWidth() / 2);
500  }
505  public static void MoveRightOutside(this RectTransform rt, float distance = 0)
506  {
507  rt.MoveRight(distance - rt.GetWidth() / 2);
508  }
513  public static void MoveTopOutside(this RectTransform rt, float distance = 0)
514  {
515  rt.MoveTop(distance - rt.GetHeight() / 2);
516  }
521  public static void MoveBottomOutside(this RectTransform rt, float distance = 0)
522  {
523  rt.MoveBottom(distance - rt.GetHeight() / 2);
524  }
525 
526 
532  public static void Move(this RectTransform rt, float x, float y)
533  {
534  rt.MoveLeft(x);
535  rt.MoveBottom(y);
536  }
541  public static void Move(this RectTransform rt, Vector2 point)
542  {
543  rt.MoveLeft(point.x);
544  rt.MoveBottom(point.y);
545  }
546 
547 
554  public static void MoveInside(this RectTransform rt, float x, float y)
555  {
556  rt.MoveLeftInside(x);
557  rt.MoveBottomInside(y);
558  }
564  public static void MoveInside(this RectTransform rt, Vector2 point)
565  {
566  rt.MoveLeftInside(point.x);
567  rt.MoveBottomInside(point.y);
568  }
569 
570 
577  public static void MoveOutside(this RectTransform rt, float x, float y)
578  {
579  rt.MoveLeftOutside(x);
580  rt.MoveBottomOutside(y);
581  }
587  public static void MoveOutside(this RectTransform rt, Vector2 point)
588  {
589  rt.MoveLeftOutside(point.x);
590  rt.MoveBottomOutside(point.y);
591  }
592 
593 
597  public static void MoveFrom(this RectTransform rt, MinMax01 anchor, Vector2 point)
598  {
599  rt.MoveFrom(anchor, point.x, point.y);
600  }
605  public static void MoveFrom(this RectTransform rt, MinMax01 anchor, float x, float y)
606  {
607  Vector2 origin = rt.AnchorToParentSpace(AnchorOrigin(anchor) - rt.AnchorOrigin());
608  rt.anchoredPosition = new Vector2(origin.x + x, origin.y + y);
609  }
610 
611 
617  public static Vector2 ParentToChildSpace(this RectTransform rt, Vector2 point)
618  {
619  return rt.ParentToChildSpace(point.x, point.y);
620  }
627  public static Vector2 ParentToChildSpace(this RectTransform rt, float x, float y)
628  {
629  float xmin = rt.GetParent().rect.xMin;
630  float ymin = rt.GetParent().rect.yMin;
631  float anchorFactorX = rt.anchorMin.x * 2 - 1;
632  float anchorFactorY = rt.anchorMin.y * 2 - 1;
633  return new Vector2(xmin + (xmin * anchorFactorX) + x, ymin + (ymin * anchorFactorY) + y);
634  }
635 
636 
643  public static Vector2 ChildToParentSpace(this RectTransform rt, float x, float y)
644  {
645  return rt.AnchorOriginParent() + new Vector2(x, y);
646  }
652  public static Vector2 ChildToParentSpace(this RectTransform rt, Vector2 point)
653  {
654  return rt.AnchorOriginParent() + point;
655  }
656 
657 
663  public static Vector2 ParentToAnchorSpace(this RectTransform rt, Vector2 point)
664  {
665  return rt.ParentToAnchorSpace(point.x, point.y);
666  }
673  public static Vector2 ParentToAnchorSpace(this RectTransform rt, float x, float y)
674  {
675  Rect parent = rt.GetParent().rect;
676  if (parent.width != 0)
677  x /= parent.width;
678  else
679  x = 0;
680 
681  if (parent.height != 0)
682  y /= parent.height;
683  else
684  y = 0;
685 
686  return new Vector2(x, y);
687  }
688 
689 
696  public static Vector2 AnchorToParentSpace(this RectTransform rt, float x, float y)
697  {
698  return new Vector2(x * rt.GetParent().rect.width, y * rt.GetParent().rect.height);
699  }
705  public static Vector2 AnchorToParentSpace(this RectTransform rt, Vector2 point)
706  {
707  return new Vector2(point.x * rt.GetParent().rect.width, point.y * rt.GetParent().rect.height);
708  }
709 
710 
711 
716  public static Vector2 AnchorOrigin(this RectTransform rt)
717  {
718  return AnchorOrigin(rt.GetAnchors());
719  }
724  public static Vector2 AnchorOrigin(MinMax01 anchor)
725  {
726  float x = anchor.min.x + (anchor.max.x - anchor.min.x) / 2;
727  float y = anchor.min.y + (anchor.max.y - anchor.min.y) / 2;
728 
729  return new Vector2(x, y);
730  }
731 
736  public static Vector2 AnchorOriginParent(this RectTransform rt)
737  {
738  return Vector2.Scale(rt.AnchorOrigin(), new Vector2(rt.GetParent().rect.width, rt.GetParent().rect.height));
739  }
740 
745  public static Canvas GetRootCanvas(this RectTransform rt)
746  {
747  Canvas rootCanvas = rt.GetComponentInParent<Canvas>();
748 
749  while (!rootCanvas.isRootCanvas)
750  rootCanvas = rootCanvas.transform.parent.GetComponentInParent<Canvas>();
751 
752  return rootCanvas;
753  }
754 
759  public static void SetProperties(this RectTransform rectTrans, RectTransform properties)
760  {
761  rectTrans.SetProperties(properties.anchoredPosition, properties.anchoredPosition3D, properties.anchorMax,
762  properties.anchorMin, properties.offsetMax, properties.offsetMin, properties.pivot, properties.sizeDelta, properties.transform);
763  }
764 
777  public static void SetProperties(this RectTransform rectTrans, Vector2 anchoredPosition, Vector3 anchoredPosition3D,
778  Vector2 anchorMax, Vector2 anchorMin, Vector2 offsetMax, Vector2 offsetMin, Vector2 pivot, Vector2 sizeDelta, Transform trans = null)
779  {
780  rectTrans.anchoredPosition = anchoredPosition;
781  rectTrans.anchoredPosition3D = anchoredPosition3D;
782  rectTrans.anchorMax = anchorMax;
783  rectTrans.anchorMin = anchorMin;
784  rectTrans.offsetMax = offsetMax;
785  rectTrans.offsetMin = offsetMin;
786  rectTrans.pivot = pivot;
787  rectTrans.sizeDelta = sizeDelta;
788  if (trans) rectTrans.transform.SetProperties(trans);
789  }
790 
795  public static void SetLerp(this RectTransform self, RectTransform a, RectTransform b, float t)
796  {
797  self.SetProperties(
798  Vector2.Lerp(a.anchoredPosition, b.anchoredPosition, t),
799  Vector3.Lerp(a.anchoredPosition3D, b.anchoredPosition3D, t),
800  Vector2.Lerp(a.anchorMax, b.anchorMax, t),
801  Vector2.Lerp(a.anchorMin, b.anchorMin, t),
802  Vector2.Lerp(a.offsetMax, b.offsetMax, t),
803  Vector2.Lerp(a.offsetMin, b.offsetMin, t),
804  Vector2.Lerp(a.pivot, b.pivot, t),
805  Vector2.Lerp(a.sizeDelta, b.sizeDelta, t)
806  );
807  self.transform.SetLerp(a.transform, b.transform, t);
808  }
809 
810  }
811 }
Class containing a minimum and max Vectors with its components between 0 and 1
Definition: MinMax01.cs:7
Extensions for the RectTransform component
static void Move(this RectTransform rt, float x, float y)
Moves the RectTransform to the given point in parent space, considering (0, 0) to be the parent's low...
static void SetRightFrom(this RectTransform rt, MinMax01 anchor, float distance)
Repositions the requested edge relative to the passed anchor.
static void SetWidth(this RectTransform rt, float width)
Sets the width of the RectTransform keeping the current anchors.
static MinMax01 GetAnchors(this RectTransform rt)
The normalized position in the parent RectTransform that the corners is anchored to.
static void MoveLeft(this RectTransform rt, float left=0)
Sets the position of the RectTransform relative to the parent's Left side, regardless of anchor setti...
static float GetHeight(this RectTransform rt)
The height of the RectTransform, measured from the Y position.
static void MoveFrom(this RectTransform rt, MinMax01 anchor, float x, float y)
Moves the RectTransform relative to an arbitrary anchor point. This is effectively like setting the a...
static void SetLerp(this RectTransform self, RectTransform a, RectTransform b, float t)
Linearly interpolates between two RectTransforms.
static float GetWidth(this RectTransform rt)
The width of the RectTransform, measured from the X position.
static void Right(this RectTransform rt, float distance)
Moves the edge to a distance towards the center from the same edge of the parent.
static void MoveRightOutside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the left edge with the parent right edge.
static void SetTopFrom(this RectTransform rt, MinMax01 anchor, float distance)
Repositions the requested edge relative to the passed anchor.
static Vector2 AnchorOrigin(this RectTransform rt)
The center of the rectangle the two anchors represent, which is the origin that a RectTransform's anc...
static void SetTop(this RectTransform rt, float top)
Sets the distance of the distance from the top edge to the parent's top edge regardless of the anchor...
static void MoveOutside(this RectTransform rt, float x, float y)
Moves the RectTransform relative to the parent's lower-left corner, respecting the RT's width and hei...
static void SetLeftFrom(this RectTransform rt, MinMax01 anchor, float distance)
Repositions the requested edge relative to the passed anchor.
static Vector2 ChildToParentSpace(this RectTransform rt, float x, float y)
Translates a point (presumably the RectTransform's anchoredPosition) into the same point on the paren...
static void MoveTopOutside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the bottom edge with the parent top edge.
static Vector2 ChildToParentSpace(this RectTransform rt, Vector2 point)
Translates a point (presumably the RectTransform's anchoredPosition) into the same point on the paren...
static void SetProperties(this RectTransform rectTrans, RectTransform properties)
Sets the RectTransform position, rotation and scale to the same values in the given RectTransform.
static Vector2 GetLeft(this RectTransform rt)
The center of the left edge.
static void SetAnchors(this RectTransform rt, MinMax01 anchors)
Sets the normalized position in the parent RectTransform that the corners is anchored to.
static void Left(this RectTransform rt, float distance)
Moves the edge to a distance towards the center from the same edge of the parent.
static void SetRelativeLeft(this RectTransform rt, float distance)
Moves the edge to the requested position relative to the current position.
static Vector2 AnchorOriginParent(this RectTransform rt)
Translates a RectTransform's anchor origin into Parent space.
static void MoveFrom(this RectTransform rt, MinMax01 anchor, Vector2 point)
Moves the RectTransform relative to an arbitrary anchor point. This is effectively like setting the a...
static void SetLeft(this RectTransform rt, float distance)
Sets the distance of the distance from the left edge to the parent's left edge regardless of the anch...
static void SetHeight(this RectTransform rt, float height)
Sets the height of the RectTransform keeping the current anchors.
static void MoveLeftOutside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the right edge with the parent left edge.
static void MoveTopInside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the child left edge with the parent left top.
static void SetBottomFrom(this RectTransform rt, MinMax01 anchor, float distance)
Repositions the requested edge relative to the passed anchor.
static void Top(this RectTransform rt, float distance)
Moves the edge to a distance towards the center from the same edge of the parent.
static void SetBottom(this RectTransform rt, float distance)
Sets the distance of the distance from the bottom edge to the parent's bottom edge regardless of the ...
static Vector2 ParentToChildSpace(this RectTransform rt, float x, float y)
Translates a point on the parent's frame of reference, with (0, 0) being the parent's lower-left hand...
static void SetRelativeTop(this RectTransform rt, float distance)
Moves the edge to the requested position relative to the current position.
static void Bottom(this RectTransform rt, float distance)
Moves the edge to a distance towards the center from the same edge of the parent.
static void SetRelativeRight(this RectTransform rt, float distance)
Moves the edge to the requested position relative to the current position.
static Vector2 GetRight(this RectTransform rt)
The center of the right edge.
static RectTransform GetParent(this RectTransform rt)
The RecTransform parent of the RectTransform.
static void MoveRightInside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the child left edge with the parent right edge.
static Vector2 ParentToAnchorSpace(this RectTransform rt, float x, float y)
Normalizes a point associated with the parent object into "Anchor Space", which is to say,...
static void MoveInside(this RectTransform rt, float x, float y)
Moves the RectTransform relative to the parent's lower-le1ft corner, respecting the RT's width and he...
static Vector2 AnchorToParentSpace(this RectTransform rt, float x, float y)
Translates a normalized "Anchor Space" coordinate into a real point on the parent's reference system.
static void MoveBottom(this RectTransform rt, float bottom=0)
Sets the position of the RectTransform relative to the parent's Bottom side, regardless of anchor set...
static Vector2 GetBottom(this RectTransform rt)
The center of the bottom edge.
static Vector2 AnchorOrigin(MinMax01 anchor)
The center of the rectangle the two anchors represent, which is the origin that a RectTransform's anc...
static void MoveOutside(this RectTransform rt, Vector2 point)
Moves the RectTransform relative to the parent's lower-left corner, respecting the RT's width and hei...
static void MoveInside(this RectTransform rt, Vector2 point)
Moves the RectTransform relative to the parent's lower-le1ft corner, respecting the RT's width and he...
static void SetRight(this RectTransform rt, float distance)
Sets the distance of the distance from the left edge to the parent's left edge regardless of the anch...
static void MoveBottomInside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the child left edge with the parent bottom edge.
static Vector2 GetSize(this RectTransform rt)
The width and the height of the RectTransform, measured from the (X,Y) position.
static void SetRelativeBottom(this RectTransform rt, float distance)
Moves the edge to the requested position relative to the current position.
static void MoveLeftInside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the child left edge with the parent left edge.
static void SetSize(this RectTransform rt, float width, float height)
Sets the width and the height of the RectTransform keeping the current anchors.
static void MoveRight(this RectTransform rt, float right=0)
Sets the position of the RectTransform relative to the parent's Right side, regardless of anchor sett...
static void MoveTop(this RectTransform rt, float top=0)
Sets the position of the RectTransform relative to the parent's Top side, regardless of anchor settin...
static Vector2 GetTop(this RectTransform rt)
The center of the top edge.
static Rect GetWorldRect(this RectTransform rt)
Get the corners of the RectTransform in world space.
static Vector2 AnchorToParentSpace(this RectTransform rt, Vector2 point)
Translates a normalized "Anchor Space" coordinate into a real point on the parent's reference system.
static Vector2 ParentToAnchorSpace(this RectTransform rt, Vector2 point)
Normalizes a point associated with the parent object into "Anchor Space", which is to say,...
static void SetProperties(this RectTransform rectTrans, Vector2 anchoredPosition, Vector3 anchoredPosition3D, Vector2 anchorMax, Vector2 anchorMin, Vector2 offsetMax, Vector2 offsetMin, Vector2 pivot, Vector2 sizeDelta, Transform trans=null)
Sets the transform properties to the given values.
static void MoveBottomOutside(this RectTransform rt, float distance=0)
Moves the RectTransform to align the top edge with the parent bottom edge.
static void Move(this RectTransform rt, Vector2 point)
Moves the RectTransform to the given point in parent space, considering (0, 0) to be the parent's low...
static void SetSize(this RectTransform rt, Vector2 size)
Sets the width and the height of the RectTransform keeping the current anchors.
static Vector2 ParentToChildSpace(this RectTransform rt, Vector2 point)
Translates a point on the parent's frame of reference, with (0, 0) being the parent's lower-left hand...
static Canvas GetRootCanvas(this RectTransform rt)
Returns the top-most-level canvas that this RectTransform is a child of.