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