RectTransform Extensions

If you write the following code at the top of your file, you have access to several extension methods for RectTransform:

using TheraBytes.BetterUi;


On any RectTransform object in your code you can call one of the following methods:

  • ExpandToParentSize(...)
  • GetPivotOffset(...)
  • MoveChildsToRetainPreviousLocations(...)
  • SetPivot(...)
  • SnapAnchorsToBorders(...)
  • SnapAnchorsToPoint(...)
  • SnapSizeAndAnchorsToChildren(...)
  • ToScreenRect(...)


Most of these methods are also used by the Snap Anchors or Smart Parent tool.

Please refer to the summary-comments in code for detailed description of each method.


Shortcuts

The methods above are also used for several Shortcuts.

Additionally, there are shortcuts to navigate in the hierarchy.

All these shortcuts are mapped to the Numpad by default:


Note that the "Enclose Children" shortcuts and the "Retain Child Positions" shortcut need the Smart Parent window to properly function, so they will open it if it is not present (the used methods SnapSizeAndAnchorsToChildren(...) and MoveChildsToRetainPreviousLocations(...) do not require the tool and can be used at runtime).


The "Select - Next ..." Shortcuts will wrap around when the last object is reached.