docs.unity.cn
    Show / Hide Table of Contents

    Class LayoutUtility

    Utility functions for querying layout elements for their minimum, preferred, and flexible sizes.

    Inheritance
    Object
    LayoutUtility
    Namespace: UnityEngine.UI
    Syntax
    public static class LayoutUtility

    Methods

    GetFlexibleHeight(RectTransform)

    Returns the flexible height of the layout element.

    Declaration
    public static float GetFlexibleHeight(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetFlexibleSize(RectTransform, Int32)

    Returns the flexible size of the layout element.

    Declaration
    public static float GetFlexibleSize(RectTransform rect, int axis)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Int32 axis

    The axis to query. This can be 0 or 1.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetFlexibleWidth(RectTransform)

    Returns the flexible width of the layout element.

    Declaration
    public static float GetFlexibleWidth(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used

    GetLayoutProperty(RectTransform, Func<ILayoutElement, Single>, Single)

    Gets a calculated layout property for the layout element with the given RectTransform.

    Declaration
    public static float GetLayoutProperty(RectTransform rect, Func<ILayoutElement, float> property, float defaultValue)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to get a property for.

    Func<ILayoutElement, Single> property

    The property to calculate.

    Single defaultValue

    The default value to use if no component on the layout element supplies the given property

    Returns
    Type Description
    Single

    The calculated value of the layout property.

    GetLayoutProperty(RectTransform, Func<ILayoutElement, Single>, Single, out ILayoutElement)

    Gets a calculated layout property for the layout element with the given RectTransform.

    Declaration
    public static float GetLayoutProperty(RectTransform rect, Func<ILayoutElement, float> property, float defaultValue, out ILayoutElement source)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to get a property for.

    Func<ILayoutElement, Single> property

    The property to calculate.

    Single defaultValue

    The default value to use if no component on the layout element supplies the given property

    ILayoutElement source

    Optional out parameter to get the component that supplied the calculated value.

    Returns
    Type Description
    Single

    The calculated value of the layout property.

    GetMinHeight(RectTransform)

    Returns the minimum height of the layout element.

    Declaration
    public static float GetMinHeight(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetMinSize(RectTransform, Int32)

    Returns the minimum size of the layout element.

    Declaration
    public static float GetMinSize(RectTransform rect, int axis)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Int32 axis

    The axis to query. This can be 0 or 1.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetMinWidth(RectTransform)

    Returns the minimum width of the layout element.

    Declaration
    public static float GetMinWidth(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetPreferredHeight(RectTransform)

    Returns the preferred height of the layout element.

    Declaration
    public static float GetPreferredHeight(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetPreferredSize(RectTransform, Int32)

    Returns the preferred size of the layout element.

    Declaration
    public static float GetPreferredSize(RectTransform rect, int axis)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Int32 axis

    The axis to query. This can be 0 or 1.

    Returns
    Type Description
    Single
    Remarks

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    GetPreferredWidth(RectTransform)

    Returns the preferred width of the layout element.

    Declaration
    public static float GetPreferredWidth(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    The RectTransform of the layout element to query.

    Returns
    Type Description
    Single

    All components on the GameObject that implement the ILayoutElement are queried. The one with the highest priority which has a value for this setting is used. If multiple componets have this setting and have the same priority, the maximum value out of those is used.

    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 12 June 2023