RectTransform
Position, size, anchor and pivot information for a rectangle.
Read time 13 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Inherits from: Transform
- Implements: IEnumerable
public sealed class RectTransform : Transform, IEnumerable
Remarks
RectTransforms are used for GUI but can also be used for other things. It's used to store and manipulate the position, size, and anchoring of a rectangle and supports various forms of scaling based on a parent RectTransform.
Note: The Inspector changes which properties are exposed based on which anchor preset is in use. For more information see Rect Transform and Basic Layout.
Properties
Property | Description |
|---|---|
| anchoredPosition | The position of the pivot of this RectTransform relative to the anchor reference point. |
| anchoredPosition3D | The 3D position of the pivot of this RectTransform relative to the anchor reference point. |
| anchorMax | The normalized position in the parent RectTransform that the upper right corner is anchored to. |
| anchorMin | The normalized position in the parent RectTransform that the lower left corner is anchored to. |
| drivenByObject | The object that is driving the values of this RectTransform. Value is null if not driven. |
| offsetMax | The offset of the upper right corner of the rectangle relative to the upper right anchor. |
| offsetMin | The offset of the lower left corner of the rectangle relative to the lower left anchor. |
| pivot | The normalized position in this RectTransform that it rotates around. |
| rect | The calculated rectangle in the local space of the Transform. |
| sendChildDimensionsChange | Whether the RectTransform notifies components when a child RectTransform changes dimensions. |
| sizeDelta | The size of this RectTransform relative to the distances between the anchors. |
Methods
Method | Description |
|---|---|
| Contains | Checks whether the world-space bounding box of this RectTransform fully contains the world-space bounding box of another RectTransform. |
| FitInsideCoplanarRectTransform | Moves and optionally shrinks this RectTransform so that it fits inside the given coplanar RectTransform. |
| ForceUpdateRectTransforms | Forces immediate processing of any pending |
| GetLocalBottom | Returns the y coordinate of the bottom edge of this RectTransform in its parent's coordinate space. |
| GetLocalCorners | Get the corners of the calculated rectangle in the local space of its Transform. |
| GetLocalLeft | Returns the x coordinate of the left edge of this RectTransform in its parent's coordinate space. |
| GetLocalRight | Returns the x coordinate of the right edge of this RectTransform in its parent's coordinate space. |
| GetLocalTop | Returns the y coordinate of the top edge of this RectTransform in its parent's coordinate space. |
| GetWorldCorners | Get the corners of the calculated rectangle in world space. |
| GetWorldRect | Returns the world-space axis-aligned bounding box of this RectTransform. |
| IsCoplanarWith | Determines whether this RectTransform is coplanar with the given RectTransform. |
| SetAnchors | Sets both anchorMin and anchorMax to the same value, collapsing the anchor to a point. |
| SetInsetAndSizeFromParentEdge | Set the distance of this rectangle relative to a specified edge of the parent rectangle, while also setting its size. |
| SetLocalBottom | Moves the bottom edge of this RectTransform to the specified position in its parent's coordinate space. |
| SetLocalLeft | Moves the left edge of this RectTransform to the specified position in its parent's coordinate space. |
| SetLocalRight | Moves the right edge of this RectTransform to the specified position in its parent's coordinate space. |
| SetLocalTop | Moves the top edge of this RectTransform to the specified position in its parent's coordinate space. |
| SetPivotAndAnchors | Sets the pivot, anchorMin, and anchorMax to the same value. |
| SetPivotWithCounterAdjust | Sets the pivot point of the |
| SetSizeWithCurrentAnchors | Sets the |
| TryFitInsideCoplanarRectTransform | Checks that this RectTransform is coplanar with the given RectTransform, then moves and optionally shrinks it to fit inside. |
Static Events
Member | Description |
|---|---|
| reapplyDrivenProperties | Event invoked when a |
Enums
Enum | Description |
|---|---|
| RectTransform.Axis | Enum to specify an axis, which can be either horizontal or vertical. |
| RectTransform.Edge | Enum used to specify one edge of a rectangle. |
| RectTransform.FitResult | Indicates the result of a RectTransform fit operation. |
Delegates
Delegate | Description |
|---|---|
| RectTransform.ReapplyDrivenProperties | Delegate type for the RectTransform.reapplyDrivenProperties event. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |