Пример #1
0
    /// <summary>
    /// With this method you can set the size of the UI object in different kind of coordinate systems.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="targetSize"></param>
    /// <param name="coordinateSystem">The coordinate system of your target size.</param>
    /// <param name="rtePivotCentered">When using this tool the Unity pivot is ignored and a pivot from this tool is used, wich is located at the lower left corner of this object, if this parameter is true then the pivot will be located at the center of this object.</param>
    public static void SetSize(this RectTransform tr, Vector2 targetSize, CoordinateSystem coordinateSystem = CoordinateSystem.IgnoreAnchorsAndPivot, bool rtePivotCentered = false)
    {
        switch (coordinateSystem)
        {
        case CoordinateSystem.IgnoreAnchors:
            RteRectTools.SetSizeIgnoringAnchors(tr, targetSize, rtePivotCentered);
            break;

        case CoordinateSystem.IgnoreAnchorsAndPivot:
            RteRectTools.SetSizeIgnoringAnchors(tr, targetSize, rtePivotCentered);
            break;

        case CoordinateSystem.IgnoreAnchorsAndPivotNormalized:
            RteRectTools.SetSizeNormalizedIgnoringAnchors(tr, targetSize, rtePivotCentered);
            break;

        case CoordinateSystem.AsChildOfCanvas:
            RteRectTools.SetSizeIgnoringAnchors(tr, RteAnchorTools.GetRectSizeFromCanvasAnchorCoordinatesSize(tr, targetSize), rtePivotCentered);
            break;

        case CoordinateSystem.AsChildOfCanvasNormalized:
            RteRectTools.SetSizeIgnoringAnchors(tr, RteAnchorTools.GetRectSizeFromCanvasAnchorCoordinatesSizeNormalized(tr, targetSize), rtePivotCentered);
            break;

        case CoordinateSystem.ScreenSpacePixels:
            RteRectTools.SetSizeIgnoringAnchors(tr, RteAnchorTools.GetRectSizeFromScreenSpaceSize(tr, targetSize), rtePivotCentered);
            break;
        }
    }