RectTransform
Position, size, anchor and pivot information for a rectangle.
Read time 12 minutesLast updated 3 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 |
|---|---|
| ForceUpdateRectTransforms | Force the recalculation of RectTransforms internal data. |
| GetLocalCorners | Get the corners of the calculated rectangle in the local space of its Transform. |
| GetWorldCorners | Get the corners of the calculated rectangle in world space. |
| SetInsetAndSizeFromParentEdge | Set the distance of this rectangle relative to a specified edge of the parent rectangle, while also setting its size. |
| SetSizeWithCurrentAnchors | Makes the RectTransform calculated rect be a given size on the specified axis. |
Static Events
Member | Description |
|---|---|
| reapplyDrivenProperties | Event that is invoked for RectTransforms that need to have their driven properties reapplied. |
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. |
Delegates
Delegate | Description |
|---|---|
| RectTransform.ReapplyDrivenProperties | Delegate used 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. |