コード例 #1
0
    /// <summary>
    /// With this method you can set the size of the UI object in different kind of coordinate systems. Returns the size as a Vector2.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="coordinateSystem">The returned size will be from the coordinate system you specify in this parameter.</param>
    public static Vector2 GetSize(this RectTransform tr, CoordinateSystem coordinateSystem = CoordinateSystem.IgnoreAnchorsAndPivot)
    {
        Vector2 result = Vector2.zero;

        switch (coordinateSystem)
        {
        case CoordinateSystem.IgnoreAnchors:
            result = RteRectTools.GetSizeIgnoringAnchors(tr);
            break;

        case CoordinateSystem.IgnoreAnchorsAndPivot:
            result = RteRectTools.GetSizeIgnoringAnchors(tr);
            break;

        case CoordinateSystem.IgnoreAnchorsAndPivotNormalized:
            result = RteRectTools.GetSizeNormalizedIgnoringAnchors(tr);
            break;

        case CoordinateSystem.AsChildOfCanvas:
            result = RteAnchorTools.GetSizeInCanvasAnchorCoordinatesFromRectSize(tr);
            break;

        case CoordinateSystem.AsChildOfCanvasNormalized:
            result = RteAnchorTools.GetSizeNormalizedInCanvasAnchorCoordinatesFromRectSize(tr);
            break;

        case CoordinateSystem.ScreenSpacePixels:
            result = RteAnchorTools.GetScreenSpaceSizeFromRectSize(tr);
            break;
        }

        return(result);
    }
コード例 #2
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;
        }
    }
コード例 #3
0
    /// <summary>
    /// Move the anchors position. This is usefull to manipulate anchors position with only a single Vector2, specially usefull for tweens and clean code.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="targetPosition"></param>
    /// <param name="coordinateSystem">The coordinate system of the anchors position you are passing.</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 the square formed by the anchors, if this parameter is true then the pivot will be located at the center of the square formed by the anchors.</param>
    /// <param name="alsoMoveTheRect">Select if you want to move the object with the anchors or only move the anchors. In most cases it's a good idea to move and resize images with thier anchors because everything becomes screen size independent.</param>
    public static void SetAnchorsPosition(this RectTransform tr, Vector2 targetPosition, AnchorsCoordinateSystem coordinateSystem = AnchorsCoordinateSystem.Default, bool rtePivotCentered = false, bool alsoMoveTheRect = true)
    {
        switch (coordinateSystem)
        {
        case AnchorsCoordinateSystem.Default:
            RteAnchorTools.SetAnchorsPosition(tr, targetPosition, rtePivotCentered, alsoMoveTheRect);
            break;

        case AnchorsCoordinateSystem.AsChildOfCanvas:
            RteAnchorTools.SetAnchorsPosition(tr, RteAnchorTools.GetAnchorCoordinateFromCanvasAnchorCoordinate(tr, targetPosition), rtePivotCentered, alsoMoveTheRect);
            break;

        case AnchorsCoordinateSystem.ScreenSpacePixels:
            RteAnchorTools.SetAnchorsPosition(tr, RteAnchorTools.GetAnchorCoordinateFromScreenSpaceCoordinate(tr, targetPosition), rtePivotCentered, alsoMoveTheRect);
            break;

        case AnchorsCoordinateSystem.AsRect:
            RteAnchorTools.SetAnchorsPosition(tr, RteAnchorTools.GetAnchorCoordianteFromRectCoordinate(tr, targetPosition), rtePivotCentered, alsoMoveTheRect);
            break;

        case AnchorsCoordinateSystem.InsideCanvas:
            RteAnchorTools.SetAnchorsPosition(tr, RteAnchorTools.GetAnchorCoordinateFromInsideOfCanvasCoordinate(tr, targetPosition), rtePivotCentered, alsoMoveTheRect);
            break;

        case AnchorsCoordinateSystem.OutsideCanvas:
            RteAnchorTools.SetAnchorsPosition(tr, RteAnchorTools.GetAnchorCoordinateFromOutsideOfCanvasCoordinate(tr, targetPosition), rtePivotCentered, alsoMoveTheRect);
            break;

        case AnchorsCoordinateSystem.OutsideContainer:
            RteAnchorTools.SetAnchorsPosition(tr, RteAnchorTools.GetAnchorCoordinateFromOutsideOfContainerCoordinate(tr, targetPosition), rtePivotCentered, alsoMoveTheRect);
            break;
        }
    }
コード例 #4
0
    /// <summary>
    /// With this method you can get the position of the UI object in different kind of coordinate systems.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="coordinateSystem"> The returned position will be from the coordinate system you specify in this parameter.</param>
    /// <param name="rtePivotCentered"> This tool has it's own pivot, the Unity pivot is ignored in all the coordinate systems except "IgnoreAnchors", the pivot of this tool 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 Vector2 GetPosition(this RectTransform tr, CoordinateSystem coordinateSystem = CoordinateSystem.IgnoreAnchorsAndPivot, bool rtePivotCentered = false)
    {
        Vector2 result = default(Vector2);

        switch (coordinateSystem)
        {
        case CoordinateSystem.IgnoreAnchorsAndPivot:
            result = RteRectTools.GetPositionIgnoringAnchorsAndPivot(tr, rtePivotCentered);
            break;

        case CoordinateSystem.IgnoreAnchors:
            result = RteRectTools.GetPositionIgnoringAnchors(tr);
            break;

        case CoordinateSystem.IgnoreAnchorsAndPivotNormalized:
            result = RteRectTools.GetPositionNormalizedIgnoringAnchorsAndPivot(tr, rtePivotCentered);
            break;

        case CoordinateSystem.AsChildOfCanvas:
            result = RteRectTools.GetPositionIgnoringAnchorsAndPivot(tr, rtePivotCentered);
            result = RteAnchorTools.GetCanvasAnchorCoordinateFromRectCoordinate(tr, result);
            break;

        case CoordinateSystem.AsChildOfCanvasNormalized:
            result = RteRectTools.GetPositionIgnoringAnchorsAndPivot(tr, rtePivotCentered);
            result = RteAnchorTools.GetCanvasAnchorCoordinateNormalizedFromRectCoordinate(tr, result);
            break;

        case CoordinateSystem.ScreenSpacePixels:
            result = RteAnchorTools.GetScreenSpaceCoordinateFromRectCoordinate(tr, RteRectTools.GetPositionIgnoringAnchorsAndPivot(tr, rtePivotCentered));
            break;
        }

        return(result);
    }
コード例 #5
0
    /// <summary>
    /// A method get the anchors size. This is usefull to manipulate anchors size with only a single Vector2, specially usefull for tweens and clean code.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="coordinateSystem">The coordinate system you want the anchors size to be returned.</param>
    public static Vector2 GetAnchorsSize(this RectTransform tr, AnchorsCoordinateSystem coordinateSystem = AnchorsCoordinateSystem.Default)
    {
        switch (coordinateSystem)
        {
        case AnchorsCoordinateSystem.Default:
            return(RteAnchorTools.GetAnchorsSize(tr));

        case AnchorsCoordinateSystem.AsChildOfCanvas:
            return(RteAnchorTools.GetSizeInCanvasAnchorCoordinatesFromAnchorsSize(tr));

        case AnchorsCoordinateSystem.ScreenSpacePixels:
            return(RteAnchorTools.GetScreenSpaceSizeFromAnchorsSize(tr));

        case AnchorsCoordinateSystem.AsRect:
            return(RteAnchorTools.GetRectSizeFromAnchorSize(tr, RteAnchorTools.GetAnchorsSize(tr)));

        case AnchorsCoordinateSystem.InsideCanvas:
            return(RteAnchorTools.GetSizeInCanvasAnchorCoordinatesFromAnchorsSize(tr));

        case AnchorsCoordinateSystem.OutsideCanvas:
            return(RteAnchorTools.GetSizeInCanvasAnchorCoordinatesFromAnchorsSize(tr));

        case AnchorsCoordinateSystem.OutsideContainer:
            return(RteAnchorTools.GetAnchorsSize(tr));
        }

        return(RteAnchorTools.GetAnchorsSize(tr));
    }
コード例 #6
0
    /// <summary>
    /// A method to resize the anchors. This is usefull to manipulate anchors size with only a single Vector2, specially usefull for tweens and clean code.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="targetSize"></param>
    /// <param name="coordinateSystem">The coordinate system of the size you are passing.</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 the square formed by the anchors, if this parameter is true then the pivot will be located at the center of the square formed by the anchors.</param>
    /// <param name="alsoResizeTheRect">Select if you want to resize the object with the anchors or only resize the anchors. In most cases it's a good idea to move and resize images with thier anchors because everything becomes screen size independent.</param>
    public static void SetAnchorsSize(this RectTransform tr, Vector2 targetSize, AnchorsCoordinateSystem coordinateSystem = AnchorsCoordinateSystem.Default, bool rtePivotCentered = false, bool alsoResizeTheRect = true)
    {
        switch (coordinateSystem)
        {
        case AnchorsCoordinateSystem.Default:
            RteAnchorTools.SetAnchorsSize(tr, targetSize, rtePivotCentered, alsoResizeTheRect);
            break;

        case AnchorsCoordinateSystem.AsChildOfCanvas:
            RteAnchorTools.SetAnchorsSize(tr, RteAnchorTools.GetAnchorsSizeFromCanvasAnchorCoordinatesSize(tr, targetSize), rtePivotCentered, alsoResizeTheRect);
            break;

        case AnchorsCoordinateSystem.ScreenSpacePixels:
            RteAnchorTools.SetAnchorsSize(tr, RteAnchorTools.GetAnchorsSizeFromScreenSpaceSize(tr, targetSize), rtePivotCentered, alsoResizeTheRect);
            break;

        case AnchorsCoordinateSystem.InsideCanvas:
            RteAnchorTools.SetAnchorsSize(tr, RteAnchorTools.GetAnchorsSizeFromCanvasAnchorCoordinatesSize(tr, targetSize), rtePivotCentered, alsoResizeTheRect);
            break;

        case AnchorsCoordinateSystem.AsRect:
            RteAnchorTools.SetAnchorsSize(tr, RteAnchorTools.GetAnchorSizeFromRectSize(tr, targetSize), rtePivotCentered, alsoResizeTheRect);
            break;

        case AnchorsCoordinateSystem.OutsideCanvas:
            RteAnchorTools.SetAnchorsSize(tr, RteAnchorTools.GetAnchorsSizeFromCanvasAnchorCoordinatesSize(tr, targetSize), rtePivotCentered, alsoResizeTheRect);
            break;

        case AnchorsCoordinateSystem.OutsideContainer:
            RteAnchorTools.SetAnchorsSize(tr, targetSize, rtePivotCentered, alsoResizeTheRect);
            break;
        }
    }
コード例 #7
0
    /// <summary>
    /// Get the anchors position. This is usefull to manipulate anchors position with only a single Vector2, specially usefull for tweens and clean code.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="coordinateSystem">The coordinate system you want the anchors position to be returned.</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 the square formed by the anchors, if this parameter is true then the pivot will be located at the center of the square formed by the anchors.</param>
    public static Vector2 GetAnchorsPosition(this RectTransform tr, AnchorsCoordinateSystem coordinateSystem = AnchorsCoordinateSystem.Default, bool rtePivotCentered = false)
    {
        switch (coordinateSystem)
        {
        case AnchorsCoordinateSystem.Default:
            return(RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered));

        case AnchorsCoordinateSystem.AsChildOfCanvas:
            return(RteAnchorTools.GetCanvasAnchorCoordinateFromAnchorCoordinate(tr, RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered)));

        case AnchorsCoordinateSystem.ScreenSpacePixels:
            return(RteAnchorTools.GetScreenSpaceCoordinateFromAnchorCoordinate(tr, RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered)));

        case AnchorsCoordinateSystem.AsRect:
            return(RteAnchorTools.GetRectCoordinateFromAnchorCoordinate(tr, RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered)));

        case AnchorsCoordinateSystem.InsideCanvas:
            return(RteAnchorTools.GetInsideOfCanvasCoordinateFromAnchorCoordinate(tr, RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered)));

        case AnchorsCoordinateSystem.OutsideCanvas:
            return(RteAnchorTools.GetOutsideOfCanvasCoordinateFromAnchorCoordinate(tr, RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered)));

        case AnchorsCoordinateSystem.OutsideContainer:
            return(RteAnchorTools.GetOutsideOfContainerCoordinateFromAnchorCoordinate(tr, RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered)));
        }

        return(RteAnchorTools.GetAnchorsPosition(tr, rtePivotCentered));
    }
コード例 #8
0
    /// <summary>
    /// With this method you can set the position of the UI object in different kind of coordinate systems.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="targetPosition"> Your target position.</param>
    /// <param name="coordinateSystem"> The coordinate system of your target position.</param>
    /// <param name="rtePivotCentered"> This tool has it's own pivot, the Unity pivot is ignored in all the coordinate systems except "IgnoreAnchors", the pivot of this tool 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 SetPosition(this RectTransform tr, Vector2 targetPosition, CoordinateSystem coordinateSystem = CoordinateSystem.IgnoreAnchorsAndPivot, bool rtePivotCentered = false)
    {
        switch (coordinateSystem)
        {
        case CoordinateSystem.IgnoreAnchors:
            RteRectTools.SetPositionIgnoringAnchors(tr, targetPosition);
            return;

        case CoordinateSystem.IgnoreAnchorsAndPivotNormalized:
            RteRectTools.SetPositionNormalizedIgnoringAnchorsAndPivot(tr, targetPosition, rtePivotCentered);
            return;

        case CoordinateSystem.AsChildOfCanvas:
            targetPosition = RteAnchorTools.GetRectCoordinateFromCanvasAnchorCoordinate(tr, targetPosition);
            break;

        case CoordinateSystem.AsChildOfCanvasNormalized:
            targetPosition = RteAnchorTools.GetRectCoordinateFromCanvasAnchorCoordinateNormalized(tr, targetPosition);
            break;

        case CoordinateSystem.ScreenSpacePixels:
            targetPosition = RteAnchorTools.GetRectCoordinateFromScreenSpaceCoordinate(tr, targetPosition);
            break;
        }

        RteRectTools.SetPositionIgnoringAnchorsAndPivot(tr, targetPosition, rtePivotCentered);
    }
コード例 #9
0
    /// <summary>
    /// Get the height not ignoring anchors from a height value that ignores anchors.
    /// </summary>
    /// <param name="transf"></param>
    /// <param name="heightIgnoringAnchors"></param>
    /// <returns></returns>
    public static float GetHeightAnchored(RectTransform transf, float heightIgnoringAnchors)
    {
        Vector2 anchorsSize = RteAnchorTools.GetAnchorsSize(transf);
        Vector2 parentSize  = GetParentSizeIgnoringAnchors(transf);

        float height = parentSize.y * anchorsSize.y - heightIgnoringAnchors;

        return(height);
    }
コード例 #10
0
    /// <summary>
    /// Get the width not ignoring anchors from a width value that ignores anchors.
    /// </summary>
    /// <param name="transf"></param>
    /// <param name="widthIgnoringAnchors"></param>
    /// <returns></returns>
    public static float GetWidthAnchored(RectTransform transf, float widthIgnoringAnchors)
    {
        Vector2 anchorsSize = RteAnchorTools.GetAnchorsSize(transf);
        Vector2 parentSize  = GetParentSizeIgnoringAnchors(transf);

        float width = parentSize.x * anchorsSize.x - widthIgnoringAnchors;

        return(width);
    }
コード例 #11
0
    public static Vector2 GetCanvasPositionFromLocalPosition(RectTransform tr, Vector2 pivotPosition)
    {
        Vector2 size     = RteRectTools.GetSizeIgnoringAnchors(tr);
        Vector2 position = RteRectTools.GetPositionIgnoringAnchorsAndPivot(tr);

        size.x *= pivotPosition.x;
        size.y *= pivotPosition.y;
        size   += position;
        return(RteAnchorTools.GetCanvasAnchorCoordinateNormalizedFromRectCoordinate(tr, size));
    }
コード例 #12
0
    /// <summary>
    /// The With and Height parameters of RectTransform gives relative to anchors values when anchors are not joined, wich is not so usefull. With this you can get the real Size of the RectTransform. Like when the anchors are joined.
    /// </summary>
    /// <param name="transf"></param>
    public static Vector2 GetSizeIgnoringAnchors(RectTransform transf)
    {
        Vector2 parentSize  = GetParentSizeIgnoringAnchors(transf);
        Vector2 anchorsSize = RteAnchorTools.GetAnchorsSize(transf);

        return(new Vector2
               (
                   parentSize.x * anchorsSize.x + transf.sizeDelta.x,
                   parentSize.y * anchorsSize.y + transf.sizeDelta.y
               ));
    }
コード例 #13
0
    /// <summary>
    /// Returns the position of the pivot point relative to the parent rect coordinates, instead of what you get with AnchoredPosition property which is the position of the pivot relative to the anchors center point.
    /// </summary>
    /// <param name="transf"></param>
    /// <returns></returns>
    public static Vector2 GetPositionIgnoringAnchors(RectTransform transf)
    {
        Vector2 anchorsSize       = RteAnchorTools.GetAnchorsSize(transf);
        Vector2 anchorsPivotedPos = new Vector2(transf.anchorMin.x + anchorsSize.x * transf.pivot.x, transf.anchorMin.y + anchorsSize.y * transf.pivot.y);
        Vector2 parentSize        = GetParentSizeIgnoringAnchors(transf);

        return(new Vector2
               (
                   transf.anchoredPosition.x + parentSize.x * anchorsPivotedPos.x,
                   transf.anchoredPosition.y + parentSize.y * anchorsPivotedPos.y
               ));
    }
コード例 #14
0
    public static Vector2 GetLocalPositionFromCanvasPosition(RectTransform transform, Vector2 canvasPosition)
    {
        Vector2 rectCoordinate = RteAnchorTools.GetRectCoordinateFromCanvasAnchorCoordinateNormalized(transform, canvasPosition);
        Vector2 position       = RteRectTools.GetPositionIgnoringAnchorsAndPivot(transform);
        Vector2 size           = RteRectTools.GetSizeIgnoringAnchors(transform);

        rectCoordinate   -= position;
        rectCoordinate.x /= size.x;
        rectCoordinate.y /= size.y;
        rectCoordinate.FixNaN();
        return(rectCoordinate);
    }
コード例 #15
0
    /// <summary>
    /// Sets the position of the object with a coordinate relative to the parent rect coordinates, instead of what you set with AnchoredPosition property which is the position relative to the anchors center point.
    /// </summary>
    /// <param name="transf"></param>
    /// <param name="newPosition"></param>
    public static void SetPositionIgnoringAnchors(RectTransform transf, Vector2 newPosition)
    {
        Vector2 anchorsSize       = RteAnchorTools.GetAnchorsSize(transf);
        Vector2 anchorsPivotedPos = new Vector2(transf.anchorMin.x + anchorsSize.x * transf.pivot.x, transf.anchorMin.y + anchorsSize.y * transf.pivot.y);
        Vector2 parentSize        = GetParentSizeIgnoringAnchors(transf);

        transf.anchoredPosition = newPosition - new Vector2
                                  (
            parentSize.x * anchorsPivotedPos.x,
            parentSize.y * anchorsPivotedPos.y
                                  );
    }
コード例 #16
0
    /// <summary>
    /// Get the size not ignoring anchors from a size value that ignores anchors.
    /// </summary>
    /// <param name="transf"></param>
    /// <param name="sizeIgnoringAnchors"></param>
    public static Vector2 GetSizeAnchored(RectTransform transf, Vector2 sizeIgnoringAnchors)
    {
        Vector2 anchorsSize = RteAnchorTools.GetAnchorsSize(transf);
        Vector2 parentSize  = GetParentSizeIgnoringAnchors(transf);

        Vector2 size = new Vector2
                       (
            parentSize.x * anchorsSize.x - sizeIgnoringAnchors.x,
            parentSize.y * anchorsSize.y - sizeIgnoringAnchors.y
                       );

        return(size);
    }
コード例 #17
0
    /// <summary>
    /// Sets the Y position of the object with the left down point as the position point instead of the pivot point as the position point, also the position is not set relative to the anchors but relative to the parent rect coordinates.
    /// </summary>
    /// <param name="transf"></param>
    /// <param name="newPositionY"></param>
    public static void SetPositionYIgnoringAnchorsAndPivot(RectTransform transf, float newPositionY, bool centerPivot = false)
    {
        Vector2 size = Vector2.zero;

        if (centerPivot)
        {
            size = GetSizeIgnoringAnchors(transf);
        }
        Vector2 newPos     = transf.anchoredPosition;
        Vector2 parentSize = GetParentSizeIgnoringAnchors(transf);

        newPos.y = newPositionY - (parentSize.y * RteAnchorTools.GetAnchorsPosition(transf, true).y) + (transf.rect.height * transf.pivot.y) - size.y * 0.5f;
        transf.anchoredPosition = newPos;
    }
コード例 #18
0
    /// <summary>
    /// Sets the position of the object with the left down point as the position point instead of the pivot point as the position point, also the position is not set relative to the anchors but relative to the parent rect coordinates.
    /// </summary>
    /// <param name="transf"></param>
    /// <param name="newPosition"></param>
    public static void SetPositionIgnoringAnchorsAndPivot(RectTransform transf, Vector2 newPosition, bool centerPivot = false)
    {
        Vector2 rectSize          = GetSizeIgnoringAnchors(transf);
        Vector2 anchorsSize       = RteAnchorTools.GetAnchorsSize(transf);
        Vector2 anchorsPivotedPos = new Vector2(transf.anchorMin.x + anchorsSize.x * transf.pivot.x, transf.anchorMin.y + anchorsSize.y * transf.pivot.y);
        Vector2 parentSize        = GetParentSizeIgnoringAnchors(transf);

        transf.anchoredPosition = newPosition - new Vector2
                                  (
            parentSize.x * anchorsPivotedPos.x - rectSize.x * transf.pivot.x,
            parentSize.y * anchorsPivotedPos.y - rectSize.y * transf.pivot.y
                                  );

        if (centerPivot)
        {
            transf.anchoredPosition -= new Vector2(rectSize.x * 0.5f, rectSize.y * 0.5f);
        }
    }