Ejemplo n.º 1
0
    public static Vector3 TransformToCenter(this dfPivotPoint pivot, Vector2 size)
    {
        switch (pivot)
        {
        case dfPivotPoint.TopLeft:
            return((Vector3) new Vector2(0.5f * size.x, 0.5f * -size.y));

        case dfPivotPoint.TopCenter:
            return((Vector3) new Vector2(0f, 0.5f * -size.y));

        case dfPivotPoint.TopRight:
            return((Vector3) new Vector2(0.5f * -size.x, 0.5f * -size.y));

        case dfPivotPoint.MiddleLeft:
            return((Vector3) new Vector2(0.5f * size.x, 0f));

        case dfPivotPoint.MiddleCenter:
            return((Vector3) new Vector2(0f, 0f));

        case dfPivotPoint.MiddleRight:
            return((Vector3) new Vector2(0.5f * -size.x, 0f));

        case dfPivotPoint.BottomLeft:
            return((Vector3) new Vector2(0.5f * size.x, 0.5f * size.y));

        case dfPivotPoint.BottomCenter:
            return((Vector3) new Vector2(0f, 0.5f * size.y));

        case dfPivotPoint.BottomRight:
            return((Vector3) new Vector2(0.5f * -size.x, 0.5f * size.y));
        }
        object[] objArray1 = new object[] { "Unhandled ", pivot.GetType().Name, " value: ", pivot };
        throw new Exception(string.Concat(objArray1));
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Returns the offset of the control's upper left corner with respect to
    /// the GameObject's Transform.localposition value
    /// </summary>
    /// <param name="pivot"></param>
    /// <returns></returns>
    public static Vector3 TransformToUpperLeft(this dfPivotPoint pivot, Vector2 size)
    {
        switch (pivot)
        {
        case dfPivotPoint.TopLeft:
            return(new Vector2(0f, 0f));

        case dfPivotPoint.TopCenter:
            return(new Vector2(0.5f * -size.x, 0f));

        case dfPivotPoint.TopRight:
            return(new Vector2(-size.x, 0f));

        case dfPivotPoint.MiddleLeft:
            return(new Vector2(0f, 0.5f * size.y));

        case dfPivotPoint.MiddleCenter:
            return(new Vector2(0.5f * -size.x, 0.5f * size.y));

        case dfPivotPoint.MiddleRight:
            return(new Vector2(-size.x, 0.5f * size.y));

        case dfPivotPoint.BottomLeft:
            return(new Vector2(0, size.y));

        case dfPivotPoint.BottomCenter:
            return(new Vector2(0.5f * -size.x, size.y));

        case dfPivotPoint.BottomRight:
            return(new Vector2(-size.x, size.y));
        }

        throw new Exception("Unhandled " + pivot.GetType().Name + " value: " + pivot);
    }
Ejemplo n.º 3
0
    public static Vector3 TransformToUpperLeft(this dfPivotPoint pivot, Vector2 size)
    {
        switch (pivot)
        {
        case dfPivotPoint.TopLeft:
        {
            return(new Vector2(0f, 0f));
        }

        case dfPivotPoint.TopCenter:
        {
            return(new Vector2(0.5f * -size.x, 0f));
        }

        case dfPivotPoint.TopRight:
        {
            return(new Vector2(-size.x, 0f));
        }

        case dfPivotPoint.MiddleLeft:
        {
            return(new Vector2(0f, 0.5f * size.y));
        }

        case dfPivotPoint.MiddleCenter:
        {
            return(new Vector2(0.5f * -size.x, 0.5f * size.y));
        }

        case dfPivotPoint.MiddleRight:
        {
            return(new Vector2(-size.x, 0.5f * size.y));
        }

        case dfPivotPoint.BottomLeft:
        {
            return(new Vector2(0f, size.y));
        }

        case dfPivotPoint.BottomCenter:
        {
            return(new Vector2(0.5f * -size.x, size.y));
        }

        case dfPivotPoint.BottomRight:
        {
            return(new Vector2(-size.x, size.y));
        }
        }
        throw new Exception(string.Concat(new object[] { "Unhandled ", pivot.GetType().Name, " value: ", pivot }));
    }