예제 #1
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;
        }
    }
예제 #2
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));
    }
예제 #3
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));
    }
예제 #4
0
    /// <summary>
    /// A method to resize the height of the anchors. This is usefull to manipulate anchors size with only a single float, specially usefull for tweens and clean code.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="targetHeight"></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 SetAnchorsHeight(this RectTransform tr, float targetHeight, AnchorsCoordinateSystem coordinateSystem = AnchorsCoordinateSystem.Default, bool rtePivotCentered = false, bool alsoResizeTheRect = true)
    {
        Vector2 currentSize = tr.GetAnchorsSize(coordinateSystem);

        tr.SetAnchorsSize(new Vector2(currentSize.x, targetHeight), coordinateSystem, rtePivotCentered, alsoResizeTheRect);
    }
예제 #5
0
    /// <summary>
    /// Move the anchors position in the Y axis. This is usefull to manipulate anchors position with only a single float, specially usefull for tweens and clean code.
    /// </summary>
    /// <param name="tr"></param>
    /// <param name="targetPositionY"></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 SetAnchorsPositionY(this RectTransform tr, float targetPositionY, AnchorsCoordinateSystem coordinateSystem = AnchorsCoordinateSystem.Default, bool rtePivotCentered = false, bool alsoMoveTheRect = true)
    {
        Vector2 currentPos = tr.GetAnchorsPosition(coordinateSystem, rtePivotCentered);

        tr.SetAnchorsPosition(new Vector2(currentPos.x, targetPositionY), coordinateSystem, rtePivotCentered, alsoMoveTheRect);
    }
예제 #6
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;
        }
    }