예제 #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;
        }
    }