Skip to main content

Class LayoutPaddingByRatio

Adjusts the padding of a LayoutGroup proportionally to the size of its RectTransform, allowing dynamic, resolution-independent layout spacing.

[AddComponentMenu("Layout/Layout Padding By Ratio", 141)]
[ExecuteAlways]
[RequireComponent(typeof(LayoutGroup))]
public class LayoutPaddingByRatio : UIBehaviour

Inheritance​

UIBehaviour→LayoutPaddingByRatio

Fields​

bottom​

Ratio (0-1) of the parent's height used for the bottom padding.

[Tooltip("Ratio (0-1) of the parent's height used for the bottom padding.")]
[SerializeField]
[Range(0, 1)]
protected float bottom

Field Value​

float

left​

Ratio (0-1) of the parent's width used for the left padding.

[Tooltip("Ratio (0-1) of the parent's width used for the left padding.")]
[SerializeField]
[Range(0, 1)]
protected float left

Field Value​

float

Ratio (0-1) of the parent's width used for the right padding.

[Tooltip("Ratio (0-1) of the parent's width used for the right padding.")]
[SerializeField]
[Range(0, 1)]
protected float right

Field Value​

float

top​

Ratio (0-1) of the parent's height used for the top padding.

[Tooltip("Ratio (0-1) of the parent's height used for the top padding.")]
[SerializeField]
[Range(0, 1)]
protected float top

Field Value​

float

Methods​

OnDisable()​

protected override void OnDisable()

OnEnable()​

protected override void OnEnable()

OnRectTransformDimensionsChange()​

protected override void OnRectTransformDimensionsChange()

OnValidate()​

Marks the layout as dirty in the Editor when properties are changed.

protected override void OnValidate()

SetDirty()​

Updates the layout's padding and marks the RectTransform as needing layout rebuild.

protected void SetDirty()

UpdatePadding()​

Calculates and applies the padding values based on the configured ratios and the current RectTransform size.

protected void UpdatePadding()
  • Fields
    • bottom
    • left
    • right
    • top
  • Methods
    • OnDisable()
    • OnEnable()
    • OnRectTransformDimensionsChange()
    • OnValidate()
    • SetDirty()
    • UpdatePadding()