Example:
private void Start()
{
(transform as RectTransform)
.AnchoredPosition(Vector2.zero)
.AnchoredPosition(0f, 0f)
.AnchoredPositionX(0f)
.AnchoredPositionY(0f)
.OffsetMax(Vector2.zero)
.OffsetMax(0f, 0f)
.OffsetMaxX(0f)
.OffsetMaxY(0f)
.OffsetMin(Vector2.zero)
.OffsetMin(0f, 0f)
.OffsetMinX(0f)
.OffsetMinY(0f)
.AnchoredPosition3D(Vector2.zero)
.AnchoredPosition3D(0f, 0f)
.AnchoredPosition3DX(0f)
.AnchoredPosition3DY(0f)
.AnchorMin(Vector2.zero)
.AnchorMin(0f, 0f)
.AnchorMinX(0f)
.AnchorMinY(0f)
.AnchorMax(Vector2.zero)
.AnchorMax(0f, 0f)
.AnchorMaxX(0f)
.AnchorMaxY(0f)
.Pivot(Vector2.zero)
.Pivot(0f, 0f)
.PivotX(0f)
.PivotY(0f)
.SizeDelta(Vector2.zero)
.SizeDelta(0f, 0f)
.SizeDeltaX(0f)
.SizeDeltaY(0f)
.SetSizeWidth(0f)
.SetSizeHeight(0f);
}
Extension:
///
/// The extension of rect transform.
///
public static class RectTransformExtension
{
#region AnchoredPosition
///
/// Set the anchored position.
///
///
///
///
public static RectTransform AnchoredPosition(this RectTransform self, Vector3 anchoredPosition)
{
self.anchoredPosition = anchoredPosition;
return self;
}
///
/// Set the anchored position.
///
///
///
///
///
public static RectTransform AnchoredPosition(this RectTransform self, float x, float y)
{
Vector2 anchoredPosition = self.anchoredPosition;
anchoredPosition.x = x;
anchoredPosition.y = y;
self.anchoredPosition = anchoredPosition;
return self;
}
///
/// Set the anchored position x value.
///
///
///
///
public static RectTransform AnchoredPositionX(this RectTransform self, float x)
{
Vector2 anchoredPosition = self.anchoredPosition;
anchoredPosition.x = x;
self.anchoredPosition = anchoredPosition;
return self;
}
///
/// Set the anchored position y value.
///
///
///
///
public static RectTransform AnchoredPositionY(this RectTransform self, float y)
{
Vector2 anchoredPosition = self.anchoredPosition;
anchoredPosition.y = y;
self.anchoredPosition = anchoredPosition;
return self;
}
#endregion
#region OffsetMax
///
/// Set the offset max.
///
///
///
///
public static RectTransform OffsetMax(this RectTransform self, Vector2 offsetMax)
{
self.offsetMax = offsetMax;
return self;
}
///
/// Set the offset max.
///
///
///
///
///
public static RectTransform OffsetMax(this RectTransform self, float x, float y)
{
Vector2 offsetMax = self.offsetMax;
offsetMax.x = x;
offsetMax.y = y;
self.offsetMax = offsetMax;
return self;
}
///
/// Set the offset max x value.
///
///
///
///
public static RectTransform OffsetMaxX(this RectTransform self, float x)
{
Vector2 offsetMax = self.offsetMax;
offsetMax.x = x;
self.offsetMax = offsetMax;
return self;
}
///
/// Set the offset max y value.
///
///
///
///
public static RectTransform OffsetMaxY(this RectTransform self, float y)
{
Vector2 offsetMax = self.offsetMax;
offsetMax.y = y;
self.offsetMax = offsetMax;
return self;
}
#endregion
#region OffsetMin
///
/// Set the offset min.
///
///
///
///
public static RectTransform OffsetMin(this RectTransform self, Vector2 offsetMin)
{
self.offsetMin = offsetMin;
return self;
}
///
/// Set the offset min.
///
///
///
///
///
public static RectTransform OffsetMin(this RectTransform self, float x, float y)
{
Vector2 offsetMin = self.offsetMin;
offsetMin.x = x;
offsetMin.y = y;
self.offsetMin = offsetMin;
return self;
}
///
/// Set the offset min x value.
///
///
///
///
public static RectTransform OffsetMinX(this RectTransform self, float x)
{
Vector2 offsetMin = self.offsetMin;
offsetMin.x = x;
self.offsetMin = offsetMin;
return self;
}
///
/// Set the offset min y value.
///
///
///
///
public static RectTransform OffsetMinY(this RectTransform self, float y)
{
Vector2 offsetMin = self.offsetMin;
offsetMin.y = y;
self.offsetMin = offsetMin;
return self;
}
#endregion
#region AnchoredPosition3D
///
/// Set the anchored position 3d.
///
///
///
///
public static RectTransform AnchoredPosition3D(this RectTransform self, Vector2 anchoredPosition3D)
{
self.anchoredPosition3D = anchoredPosition3D;
return self;
}
///
/// Set the anchored position 3d.
///
///
///
///
///
public static RectTransform AnchoredPosition3D(this RectTransform self, float x, float y)
{
Vector2 anchoredPosition3D = self.anchoredPosition3D;
anchoredPosition3D.x = x;
anchoredPosition3D.y = y;
self.anchoredPosition3D = anchoredPosition3D;
return self;
}
///
/// Set the anchored position 3d x value.
///
///
///
///
public static RectTransform AnchoredPosition3DX(this RectTransform self, float x)
{
Vector2 anchoredPosition3D = self.anchoredPosition3D;
anchoredPosition3D.x = x;
self.anchoredPosition3D = anchoredPosition3D;
return self;
}
///
/// Set the anchored position 3d y value.
///
///
///
///
public static RectTransform AnchoredPosition3DY(this RectTransform self, float y)
{
Vector2 anchoredPosition3D = self.anchoredPosition3D;
anchoredPosition3D.y = y;
self.anchoredPosition3D = anchoredPosition3D;
return self;
}
#endregion
#region AnchorMin
///
/// Set the anchor min.
///
///
///
///
public static RectTransform AnchorMin(this RectTransform self, Vector2 anchorMin)
{
self.anchorMin = anchorMin;
return self;
}
///
/// Set the anchor min.
///
///
///
///
///
public static RectTransform AnchorMin(this RectTransform self, float x, float y)
{
Vector2 anchorMin = self.anchorMin;
anchorMin.x = x;
anchorMin.y = y;
self.anchorMin = anchorMin;
return self;
}
///
/// Set the anchor min x value.
///
///
///
///
public static RectTransform AnchorMinX(this RectTransform self, float x)
{
Vector2 anchorMin = self.anchorMin;
anchorMin.x = x;
self.anchorMin = anchorMin;
return self;
}
///
/// Set the anchor min y value.
///
///
///
///
public static RectTransform AnchorMinY(this RectTransform self, float y)
{
Vector2 anchorMin = self.anchorMin;
anchorMin.y = y;
self.anchorMin = anchorMin;
return self;
}
#endregion
#region AnchorMax
///
/// Set the anchor max.
///
///
///
///
public static RectTransform AnchorMax(this RectTransform self, Vector2 anchorMax)
{
self.anchorMax = anchorMax;
return self;
}
///
/// Set the anchor max.
///
///
///
///
///
public static RectTransform AnchorMax(this RectTransform self, float x, float y)
{
Vector2 anchorMax = self.anchorMax;
anchorMax.x = x;
anchorMax.y = y;
self.anchorMax = anchorMax;
return self;
}
///
/// Set the anchor max x value.
///
///
///
///
public static RectTransform AnchorMaxX(this RectTransform self, float x)
{
Vector2 anchorMax = self.anchorMax;
anchorMax.x = x;
self.anchorMax = anchorMax;
return self;
}
///
/// Set the anchor max y value.
///
///
///
///
public static RectTransform AnchorMaxY(this RectTransform self, float y)
{
Vector2 anchorMax = self.anchorMax;
anchorMax.y = y;
self.anchorMax = anchorMax;
return self;
}
#endregion
#region Pivot
///
/// Set the pivot.
///
///
///
///
public static RectTransform Pivot(this RectTransform self, Vector2 pivot)
{
self.pivot = pivot;
return self;
}
///
/// Set the pivot.
///
///
///
///
///
public static RectTransform Pivot(this RectTransform self, float x, float y)
{
Vector2 pivot = self.pivot;
pivot.x = x;
pivot.y = y;
self.pivot = pivot;
return self;
}
///
/// Set the pivot x value.
///
///
///
///
public static RectTransform PivotX(this RectTransform self, float x)
{
Vector2 pivot = self.pivot;
pivot.x = x;
self.pivot = pivot;
return self;
}
///
/// Set the pivot y value.
///
///
///
///
public static RectTransform PivotY(this RectTransform self, float y)
{
Vector2 pivot = self.pivot;
pivot.y = y;
self.pivot = pivot;
return self;
}
#endregion
#region SizeDelta
///
/// Set the size delta.
///
///
///
///
public static RectTransform SizeDelta(this RectTransform self, Vector2 sizeDelta)
{
self.sizeDelta = sizeDelta;
return self;
}
///
/// Set the size delta.
///
///
///
///
///
public static RectTransform SizeDelta(this RectTransform self, float x, float y)
{
Vector2 sizeDelta = self.sizeDelta;
sizeDelta.x = x;
sizeDelta.y = y;
self.sizeDelta = sizeDelta;
return self;
}
///
/// Set the size delta x value.
///
///
///
///
public static RectTransform SizeDeltaX(this RectTransform self, float x)
{
Vector2 sizeDelta = self.sizeDelta;
sizeDelta.x = x;
self.sizeDelta = sizeDelta;
return self;
}
///
/// Set the size delta y value.
///
///
///
///
public static RectTransform SizeDeltaY(this RectTransform self, float y)
{
Vector2 sizeDelta = self.sizeDelta;
sizeDelta.y = y;
self.sizeDelta = sizeDelta;
return self;
}
#endregion
#region Size
///
/// Set width with current anchors.
///
///
///
///
public static RectTransform SetSizeWidth(this RectTransform self, float width)
{
self.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
return self;
}
///
/// Set height with current anchors.
///
///
///
///
public static RectTransform SetSizeHeight(this RectTransform self, float height)
{
self.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
return self;
}
#endregion
}