Пример #1
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));
    }