Ejemplo n.º 1
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;
        }
    }