Version 3.3.1.2

RectExtensions class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public static class RectExtensions
Defines a collection of handy Rect transformation methods, that can chained together for complex behaviour. Note that only the TakeX method defined here actually change the original Rect; the rest instead return a new transformed Rect.
Inheritance
  • System.Object
  • RectExtensions

Methods

AddMax(Rect, Vector2)
Adds to a Rect's max position.
public static Rect AddMax(this Rect rect, Vector2 value)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 value

The value to add.

Returns
UnityEngine.Rect

AddMin(Rect, Vector2)
Adds to a Rect's min position.
public static Rect AddMin(this Rect rect, Vector2 value)
Parameters
UnityEngine.Rect rect

The original rect.

UnityEngine.Vector2 value

The value to add.

Returns
UnityEngine.Rect

AddPosition(Rect, Single, Single)
Moves a Rect's position by the specified amount.
public static Rect AddPosition(this Rect rect, float x, float y)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single x

The x.

System.Single y

The y.

Returns
UnityEngine.Rect

AddPosition(Rect, Vector2)
Moves a Rect's position by the specified amount.
public static Rect AddPosition(this Rect rect, Vector2 move)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 move

The change in position.

Returns
UnityEngine.Rect

AddX(Rect, Single)
Adds to a Rect's X position.
public static Rect AddX(this Rect rect, float x)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single x

The value to add.

Returns
UnityEngine.Rect

AddXMax(Rect, Single)
Adds to a Rect's X max position.
public static Rect AddXMax(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to add.

Returns
UnityEngine.Rect

AddXMin(Rect, Single)
Adds to a Rect's X min position.
public static Rect AddXMin(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to add.

Returns
UnityEngine.Rect

AddY(Rect, Single)
Adds to a Rect's Y position.
public static Rect AddY(this Rect rect, float y)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single y

The value to add.

Returns
UnityEngine.Rect

AddYMax(Rect, Single)
Adds to a Rect's Y max position.
public static Rect AddYMax(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to add.

Returns
UnityEngine.Rect

AddYMin(Rect, Single)
Adds to a Rect's Y min position.
public static Rect AddYMin(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to add.

Returns
UnityEngine.Rect

AlignBottom(Rect, Single)
Returns a Rect, with the specified height, that has been aligned to the bottom of the original Rect.
public static Rect AlignBottom(this Rect rect, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

AlignCenter(Rect, Single)
Returns a Rect, with the specified width, that has been aligned to horizontal center of the original Rect.
public static Rect AlignCenter(this Rect rect, float width)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

Returns
UnityEngine.Rect

AlignCenter(Rect, Single, Single)
Returns a Rect, with the specified width and height in the center of the provided rect.
public static Rect AlignCenter(this Rect rect, float width, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

AlignCenterX(Rect, Single)
Returns a Rect, with the specified width, that has been aligned horizontally to the center of the original rect.
public static Rect AlignCenterX(this Rect rect, float width)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

Returns
UnityEngine.Rect

AlignCenterXY(Rect, Single)
Returns a Rect, with the specified width and height, that has been aligned horizontally and vertically to the center of the original rect.
public static Rect AlignCenterXY(this Rect rect, float size)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single size

The desired width and height of the new Rect.

Returns
UnityEngine.Rect

AlignCenterXY(Rect, Single, Single)
Returns a Rect, with the specified width and height, that has been aligned horizontally and vertically to the center of the original rect.
public static Rect AlignCenterXY(this Rect rect, float width, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

AlignCenterY(Rect, Single)
Returns a Rect, with the specified height, that has been aligned vertically to the center of the original rect.
public static Rect AlignCenterY(this Rect rect, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

AlignLeft(Rect, Single)
Returns a Rect, with the specified width, that has been aligned to the left of the original Rect.
public static Rect AlignLeft(this Rect rect, float width)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

Returns
UnityEngine.Rect

AlignMiddle(Rect, Single)
Returns a Rect, with the specified height, that has been aligned to the vertical middle of the original Rect.
public static Rect AlignMiddle(this Rect rect, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

AlignRight(Rect, Single)
Returns a Rect, with the specified width, that has been aligned to the right of the original Rect.
public static Rect AlignRight(this Rect rect, float width)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

Returns
UnityEngine.Rect

AlignRight(Rect, Single, Boolean)
Returns a Rect, with the specified width, that has been aligned to the right of the original Rect.
public static Rect AlignRight(this Rect rect, float width, bool clamp)
Parameters
UnityEngine.Rect rect

System.Single width

System.Boolean clamp

Returns
UnityEngine.Rect

AlignTop(Rect, Single)
Returns a Rect, with the specified height, that has been aligned to the top of the original Rect.
public static Rect AlignTop(this Rect rect, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

Expand(Rect, Single)
Returns a Rect that has been expanded by the specified amount.
public static Rect Expand(this Rect rect, float expand)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single expand

The desired expansion.

Returns
UnityEngine.Rect

Expand(Rect, Single, Single)
Returns a Rect that has been expanded by the specified amount.
public static Rect Expand(this Rect rect, float horizontal, float vertical)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single horizontal

The desired expansion on the X-axis.

System.Single vertical

The desired expansion on the Y-axis.

Returns
UnityEngine.Rect

Expand(Rect, Single, Single, Single, Single)
Returns a Rect that has been expanded by the specified amount.
public static Rect Expand(this Rect rect, float left, float right, float top, float bottom)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single left

The desired expansion on the left.

System.Single right

The desired expansion on the right.

System.Single top

The desired expansion on the top.

System.Single bottom

The desired expansion on the bottom.

Returns
UnityEngine.Rect

ExpandTo(Rect, Vector2)
Expands a rect to contain a given position.
public static Rect ExpandTo(this Rect rect, Vector2 pos)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 pos

The position to expand the rect towards.

Returns
UnityEngine.Rect

HorizontalPadding(Rect, Single)
Returns a Rect that has been inserted by the specified amount on the X-axis.
public static Rect HorizontalPadding(this Rect rect, float padding)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single padding

The desired padding.

Returns
UnityEngine.Rect

HorizontalPadding(Rect, Single, Single)
Returns a Rect that has been inserted by the specified amount on the X-axis.
public static Rect HorizontalPadding(this Rect rect, float left, float right)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single left

Desired padding on the left side.

System.Single right

Desired padding on the right side.

Returns
UnityEngine.Rect

IsPlaceholder(Rect)
Determines if an UnityEngine.Rect is a placeholder; usually (0, 0, 1, 1) in Layout.
public static bool IsPlaceholder(this Rect rect)
Parameters
UnityEngine.Rect rect

The original UnityEngine.Rect.

Returns
System.Boolean

true if the UnityEngine.Rect is equal to (0, 0, 0, 0) or (0, 0, 1, 1); otherwise false.

MaxHeight(Rect, Single)
Sets a Rect's height, if it is greater than the specified value.
public static Rect MaxHeight(this Rect rect, float maxHeight)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single maxHeight

The desired max height.

Returns
UnityEngine.Rect

MaxWidth(Rect, Single)
Sets a Rect's width, if it is greater than the specified value.
public static Rect MaxWidth(this Rect rect, float maxWidth)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single maxWidth

The desired max width.

Returns
UnityEngine.Rect

MinHeight(Rect, Single)
Sets a Rect's height, if it is less than the specified value.
public static Rect MinHeight(this Rect rect, float minHeight)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single minHeight

The desired min height.

Returns
UnityEngine.Rect

MinWidth(Rect, Single)
Sets a Rect's width, if it is less than the specified value.
public static Rect MinWidth(this Rect rect, float minWidth)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single minWidth

The desired min width.

Returns
UnityEngine.Rect

Padding(Rect, Single)
Returns a Rect that has been inserted by the specified amount.
public static Rect Padding(this Rect rect, float padding)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single padding

The desired padding.

Returns
UnityEngine.Rect

Padding(Rect, Single, Single)
Returns a Rect that has been inserted by the specified amount.
public static Rect Padding(this Rect rect, float horizontal, float vertical)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single horizontal

The desired horizontal padding.

System.Single vertical

The desired vertical padding.

Returns
UnityEngine.Rect

Padding(Rect, Single, Single, Single, Single)
Returns a Rect that has been inserted by the specified amount.
public static Rect Padding(this Rect rect, float left, float right, float top, float bottom)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single left

The desired padding on the left.

System.Single right

The desired padding on the right.

System.Single top

The desired padding on the top.

System.Single bottom

The desired padding on the bottom.

Returns
UnityEngine.Rect

ResetPosition(Rect)
Resets a Rect's position to zero.
public static Rect ResetPosition(this Rect rect)
Parameters
UnityEngine.Rect rect

The original Rect.

Returns
UnityEngine.Rect

SetCenter(Rect, Single, Single)
Moves a Rect to the specified center position.
public static Rect SetCenter(this Rect rect, float x, float y)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single x

The desired center X position.

System.Single y

The desired center Y position.

Returns
UnityEngine.Rect

SetCenter(Rect, Vector2)
Moves a Rect to the specified center position.
public static Rect SetCenter(this Rect rect, Vector2 center)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 center

The desired center position.

Returns
UnityEngine.Rect

SetCenterX(Rect, Single)
Moves a Rect to the specified center X position.
public static Rect SetCenterX(this Rect rect, float x)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single x

The desired center x position.

Returns
UnityEngine.Rect

SetCenterY(Rect, Single)
Moves a Rect to the specified center Y position.
public static Rect SetCenterY(this Rect rect, float y)
Parameters
UnityEngine.Rect rect

The desired original Rect.

System.Single y

The desired desired center y position.

Returns
UnityEngine.Rect

SetHeight(Rect, Single)
Returns a Rect with the specified height.
public static Rect SetHeight(this Rect rect, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

SetMax(Rect, Vector2)
Sets a Rect's max position.
public static Rect SetMax(this Rect rect, Vector2 max)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 max

The desired max position.

Returns
UnityEngine.Rect

SetMin(Rect, Vector2)
Sets the min position of a Rect.
public static Rect SetMin(this Rect rect, Vector2 min)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 min

The desired min position.

Returns
UnityEngine.Rect

SetPosition(Rect, Vector2)
Moves a Rect to the specified position.
public static Rect SetPosition(this Rect rect, Vector2 position)
Parameters
UnityEngine.Rect rect

The orignal Rect.

UnityEngine.Vector2 position

The desired position.

Returns
UnityEngine.Rect

SetSize(Rect, Single)
Returns a Rect with the specified size.
public static Rect SetSize(this Rect rect, float widthAndHeight)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single widthAndHeight

The desired width and height of the new Rect.

Returns
UnityEngine.Rect

SetSize(Rect, Single, Single)
Returns a Rect with the specified size.
public static Rect SetSize(this Rect rect, float width, float height)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

System.Single height

The desired height of the new Rect.

Returns
UnityEngine.Rect

SetSize(Rect, Vector2)
Returns a Rect with the specified size.
public static Rect SetSize(this Rect rect, Vector2 size)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 size

The desired size of the new Rect.

Returns
UnityEngine.Rect

SetWidth(Rect, Single)
Returns a Rect with the specified width.
public static Rect SetWidth(this Rect rect, float width)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single width

The desired width of the new Rect.

Returns
UnityEngine.Rect

SetX(Rect, Single)
Sets a Rect's X position.
public static Rect SetX(this Rect rect, float x)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single x

The desired X position.

Returns
UnityEngine.Rect

SetXMax(Rect, Single)
Sets a Rect's X max position.
public static Rect SetXMax(this Rect rect, float xMax)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single xMax

The desired X max position.

Returns
UnityEngine.Rect

SetXMin(Rect, Single)
Sets a Rect's X min position.
public static Rect SetXMin(this Rect rect, float xMin)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single xMin

The desired min X position.

Returns
UnityEngine.Rect

SetY(Rect, Single)
Sets a Rect's Y position.
public static Rect SetY(this Rect rect, float y)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single y

The desired Y position.

Returns
UnityEngine.Rect

SetYMax(Rect, Single)
Sets a Rect's Y max position.
public static Rect SetYMax(this Rect rect, float yMax)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single yMax

The desired Y max position.

Returns
UnityEngine.Rect

SetYMin(Rect, Single)
Sets a Rect's Y min position.
public static Rect SetYMin(this Rect rect, float yMin)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single yMin

The desired Y min.

Returns
UnityEngine.Rect

Split(Rect, Int32, Int32)
Splits a Rect horizontally into the specified number of sub-rects, and returns a sub-rect for the specified index.
public static Rect Split(this Rect rect, int index, int count)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Int32 index

The index for the subrect. Includes 0, and excludes count.

System.Int32 count

The amount of subrects the Rect should be split into.

Returns
UnityEngine.Rect

SplitGrid(Rect, Single, Single, Int32)
Splits a Rect into a grid from left to right and then down.
public static Rect SplitGrid(this Rect rect, float width, float height, int index)
Parameters
UnityEngine.Rect rect

The original rect.

System.Single width

The width of a grid cell.

System.Single height

The height of a grid cell.

System.Int32 index

The index of the grid cell.

Returns
UnityEngine.Rect

SplitTableGrid(Rect, Int32, Single, Int32)
Splits a Rect into a grid from left to right and then down.
public static Rect SplitTableGrid(this Rect rect, int columnCount, float rowHeight, int index)
Parameters
UnityEngine.Rect rect

System.Int32 columnCount

System.Single rowHeight

System.Int32 index

Returns
UnityEngine.Rect

SplitVertical(Rect, Int32, Int32)
Splits a Rect vertically into the specified number of sub-rects, and returns a sub-rect for the specified index.
public static Rect SplitVertical(this Rect rect, int index, int count)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Int32 index

The index for the subrect. Includes 0, and excludes count.

System.Int32 count

The amount of subrects the Rect should be split into.

Returns
UnityEngine.Rect

SubMax(Rect, Vector2)
Subtracts a Rect's max position.
public static Rect SubMax(this Rect rect, Vector2 value)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 value

The value to add.

Returns
UnityEngine.Rect

SubMin(Rect, Vector2)
Subtracts a Rect's min position.
public static Rect SubMin(this Rect rect, Vector2 value)
Parameters
UnityEngine.Rect rect

The original Rect.

UnityEngine.Vector2 value

The vlaue to subtract.

Returns
UnityEngine.Rect

SubX(Rect, Single)
Subtracts from a Rect's X position.
public static Rect SubX(this Rect rect, float x)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single x

The value to subtract.

Returns
UnityEngine.Rect

SubXMax(Rect, Single)
Subtracts a Rect's X max position.
public static Rect SubXMax(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to subtract.

Returns
UnityEngine.Rect

SubXMin(Rect, Single)
Subtracts from a Rect's X min position.
public static Rect SubXMin(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to subtract.

Returns
UnityEngine.Rect

SubY(Rect, Single)
Subtracts a Rect's Y position.
public static Rect SubY(this Rect rect, float y)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single y

The value to subtract.

Returns
UnityEngine.Rect

SubYMax(Rect, Single)
Subtracts from a Rect's Y max position.
public static Rect SubYMax(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to subtract.

Returns
UnityEngine.Rect

SubYMin(Rect, Single)
Subtracts a Rect's Y min position.
public static Rect SubYMin(this Rect rect, float value)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single value

The value to subtract.

Returns
UnityEngine.Rect

TakeFromBottom(ref Rect, Single)
public static Rect TakeFromBottom(this ref Rect rect, float height)
Parameters
UnityEngine.Rect rect

System.Single height

Returns
UnityEngine.Rect

TakeFromDir(ref Rect, Single, Direction)
public static Rect TakeFromDir(this ref Rect rect, float width, Direction direction)
Parameters
UnityEngine.Rect rect

System.Single width

Direction direction

Returns
UnityEngine.Rect

TakeFromLeft(ref Rect, Single)
public static Rect TakeFromLeft(this ref Rect rect, float width)
Parameters
UnityEngine.Rect rect

System.Single width

Returns
UnityEngine.Rect

TakeFromRight(ref Rect, Single)
public static Rect TakeFromRight(this ref Rect rect, float width)
Parameters
UnityEngine.Rect rect

System.Single width

Returns
UnityEngine.Rect

TakeFromTop(ref Rect, Single)
public static Rect TakeFromTop(this ref Rect rect, float height)
Parameters
UnityEngine.Rect rect

System.Single height

Returns
UnityEngine.Rect

VerticalPadding(Rect, Single)
Returns a Rect that has been inserted by the specified amount on the Y-axis.
public static Rect VerticalPadding(this Rect rect, float padding)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single padding

The desired padding.

Returns
UnityEngine.Rect

VerticalPadding(Rect, Single, Single)
Returns a Rect that has been inserted by the specified amount on the Y-axis.
public static Rect VerticalPadding(this Rect rect, float top, float bottom)
Parameters
UnityEngine.Rect rect

The original Rect.

System.Single top

The desired padding on the top.

System.Single bottom

The desired padding on the bottom.

Returns
UnityEngine.Rect