/// <summary>
    /// Returns anchor position for a given parent and fallback to Screen if parent is null.
    /// </summary>
    /// <param name="sprite">Provided parent</param>
    /// <param name="yAnchor">Vertical anchor</param>
    /// <param name="xAnchor">Horizontal anchor</param>
    /// <returns>Adjusted anchor position</returns>
    private static Vector3 parentAnchorPosition(IPositionable sprite, UIyAnchor yAnchor, UIxAnchor xAnchor)
    {
        Vector3   position;
        float     width, height;
        UIxAnchor originUIxAnchor = UIxAnchor.Left;
        UIyAnchor originUIyAnchor = UIyAnchor.Top;

        // Determine correct parent values
        if (sprite == null)
        {
            position = Vector3.zero;
            width    = Screen.width;
            height   = Screen.height;
        }
        else
        {
            position        = sprite.position;
            width           = sprite.width;
            height          = sprite.height;
            originUIxAnchor = sprite.anchorInfo.OriginUIxAnchor;
            originUIyAnchor = sprite.anchorInfo.OriginUIyAnchor;
        }

        // Adjust anchor offset
        position.x += UIRelative.xAnchorAdjustment(xAnchor, width, originUIxAnchor);
        position.y -= UIRelative.yAnchorAdjustment(yAnchor, height, originUIyAnchor);

        return(position);
    }
Esempio n. 2
0
 /// <summary>
 /// Pixels to offset from the anchor.  If the anchor is right, the width will be used to make the offset
 /// from the right-most point of the sprite.
 /// </summary>
 public static float xPixelsFrom( UIxAnchor anchor, int pixelOffset, float width = 0 )
 {
     switch( anchor )
     {
         case UIxAnchor.Left:
             return pixelOffset;
         case UIxAnchor.Right:
             return Screen.width - pixelOffset - width;
     }
     return 0f;
 }
Esempio n. 3
0
 public static float xPixelsFrom( UIxAnchor anchor, int pixelOffset, float width )
 {
     switch( anchor )
     {
         case UIxAnchor.Left:
             return pixelOffset * pixelDensityMultiplier();
         case UIxAnchor.Right:
             return Screen.width - pixelOffset*pixelDensityMultiplier() - width;
     }
     return 0f;
 }
Esempio n. 4
0
 public static float xPercentFrom( UIxAnchor anchor, float percentOffset, float width )
 {
     switch( anchor )
     {
         case UIxAnchor.Left:
             return percentOffset * Screen.width;
         case UIxAnchor.Right:
             return Screen.width - ( percentOffset * Screen.width ) - width;
     }
     return 0f;
 }
Esempio n. 5
0
    /// <summary>
    /// Pixels to offset from the anchor.  If the anchor is right, the width will be used to make the offset
    /// from the right-most point of the sprite.
    /// </summary>
    public static float xPixelsFrom(UIxAnchor anchor, int pixelOffset, float width = 0)
    {
        switch (anchor)
        {
        case UIxAnchor.Left:
            return(pixelOffset);

        case UIxAnchor.Right:
            return(Screen.width - pixelOffset - width);
        }
        return(0f);
    }
Esempio n. 6
0
    /// <summary>
    /// Calculates horizontal pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float xPixelsFrom(UIxAnchor anchor, float pixelOffset)
    {
        // Get initial offset
        float offset = pixelOffset * UI.scaleFactor;

        // If anchor is right the offset is flipped
        if (anchor == UIxAnchor.Right)
        {
            offset = -offset;
        }
        return(offset);
    }
Esempio n. 7
0
    /// <summary>
    /// Calculates offset based on screen width percentage.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="width">Parent width</param>
    /// <param name="percentOffset">Percentage offset - 1 is 100%</param>
    /// <returns></returns>
    public static float xPercentFrom(UIxAnchor anchor, float width, float percentOffset)
    {
        // Get inital offset
        float offset = width * percentOffset;

        // If anchor is right the offset is flipped
        if (anchor == UIxAnchor.Right)
        {
            offset = -offset;
        }
        return(offset);
    }
Esempio n. 8
0
    /// <summary>
    /// Calculates fixed horizontal pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float xPixelsTo(UIxAnchor anchor, float offset)
    {
        // Get initial fixed offset
        float pixelOffset = offset / pixelDensityMultiplier();

        // If anchor is right the fixed offset is flipped
        if (anchor == UIxAnchor.Right)
        {
            pixelOffset = -pixelOffset;
        }
        return(pixelOffset);
    }
Esempio n. 9
0
    /// <summary>
    /// Calculates horizontal pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float xPixelsFrom(UIxAnchor anchor, float pixelOffset)
    {
        // Get initial offset
        float offset = pixelOffset * pixelDensityMultiplier();

        // If anchor is right the offset is flipped
        if (anchor == UIxAnchor.Right)
        {
            offset = -offset;
        }
        return(offset);
    }
Esempio n. 10
0
    /// <summary>
    /// Calculates offset based on screen width percentage.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="width">Parent width</param>
    /// <param name="percentOffset">Percentage offset - 1 is 100%</param>
    /// <returns></returns>
    public static float xPercentFrom( UIxAnchor anchor, float width, float percentOffset )
    {
        // Get inital offset
        float offset = width * percentOffset;
		
        // If anchor is right the offset is flipped
        if( anchor == UIxAnchor.Right )
        {
            offset = -offset;
        }
        return offset;
    }
Esempio n. 11
0
    /// <summary>
    /// Calculates fixed horizontal pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float xPixelsTo(UIxAnchor anchor, float offset)
    {
        // Get initial fixed offset
        float pixelOffset = offset / UI.scaleFactor;

        // If anchor is right the fixed offset is flipped
        if (anchor == UIxAnchor.Right)
        {
            pixelOffset = -pixelOffset;
        }
        return(pixelOffset);
    }
Esempio n. 12
0
    /// <summary>
    /// Percent to offset from the anchor.  If the anchor is right, the width will be used to make the offset
    /// from the right-most point of the sprite.
    /// </summary>
    public static float xPercentFrom(UIxAnchor anchor, float percentOffset, float width = 0)
    {
        switch (anchor)
        {
        case UIxAnchor.Left:
            return(percentOffset * Screen.width);

        case UIxAnchor.Right:
            return(Screen.width - (percentOffset * Screen.width) - width);
        }
        return(0f);
    }
Esempio n. 13
0
    /// <summary>
    /// Calculates screen width percentage based on offset.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="width">Parent width</param>
    /// <param name="offset">Position offset</param>
    /// <returns></returns>
    public static float xPercentTo( UIxAnchor anchor, float width, float offset )
    {
        if (width == 0f) return 0f;

        // Get initial percentage
        float percentOffset = offset / width;
		
        // If anchor is right the percentage is flipped
        if( anchor == UIxAnchor.Right )
        {
            percentOffset = -percentOffset;
        }
        return percentOffset;
    }
Esempio n. 14
0
    /// <summary>
    /// Finds horizontal adjustment for anchor, based on width and origin of sprite.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="width">Sprite width</param>
    /// <param name="originAnchor">Sprite origin anchor</param>
    /// <returns></returns>
    public static float xAnchorAdjustment(UIxAnchor anchor, float width, UIxAnchor originAnchor)
    {
        var adjustment = 0f;

        switch (anchor)
        {
        case UIxAnchor.Left:
        {
            if (originAnchor == UIxAnchor.Center)
            {
                adjustment -= width / 2f;
            }
            else if (originAnchor == UIxAnchor.Right)
            {
                adjustment -= width;
            }
            break;
        }

        case UIxAnchor.Right:
        {
            if (originAnchor == UIxAnchor.Left)
            {
                adjustment += width;
            }
            else if (originAnchor == UIxAnchor.Center)
            {
                adjustment += width / 2f;
            }
            break;
        }

        case UIxAnchor.Center:
        {
            if (originAnchor == UIxAnchor.Left)
            {
                adjustment += width / 2f;
            }
            else if (originAnchor == UIxAnchor.Right)
            {
                adjustment -= width / 2f;
            }
            break;
        }
        }

        return(adjustment);
    }
Esempio n. 15
0
    /// <summary>
    /// Calculates screen width percentage based on offset.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="width">Parent width</param>
    /// <param name="offset">Position offset</param>
    /// <returns></returns>
    public static float xPercentTo(UIxAnchor anchor, float width, float offset)
    {
        if (width == 0f)
        {
            return(0f);
        }

        // Get initial percentage
        float percentOffset = offset / width;

        // If anchor is right the percentage is flipped
        if (anchor == UIxAnchor.Right)
        {
            percentOffset = -percentOffset;
        }
        return(percentOffset);
    }
    /// <summary>
    /// Positions a sprite relatively to the top-left corner of its parent, with specific local anchors.
    /// Values are percentage of screen width/height to move away from the parent.
    /// </summary>
    /// <param name="sprite"></param>
    /// <param name="percentFromTop">Percentage from top - positive values places the sprite closer to the bottom</param>
    /// <param name="percentFromLeft">Percentage from left - positive values places the sprite closer to the right</param>
    /// <param name="yAnchor">Sprite vertical anchor</param>
    /// <param name="xAnchor">Sprite horizontal anchor</param>
    public static void positionFromTopLeft( this IPositionable sprite, float percentFromTop, float percentFromLeft, UIyAnchor yAnchor, UIxAnchor xAnchor )
    {
        // Update anchor information
        UIAnchorInfo anchorInfo = sprite.anchorInfo;
        anchorInfo.ParentUIxAnchor = UIxAnchor.Left;
        anchorInfo.ParentUIyAnchor = UIyAnchor.Top;
        anchorInfo.UIxAnchor = xAnchor;
        anchorInfo.UIyAnchor = yAnchor;
        anchorInfo.OffsetX = percentFromLeft;
        anchorInfo.OffsetY = percentFromTop;
        anchorInfo.UIPrecision = UIPrecision.Percentage;

        // Set new anchor information
        sprite.anchorInfo = anchorInfo;

        // Refresh position
        sprite.refreshPosition();
    }
    /// <summary>
    /// Positions a sprite relatively to the bottom-left corner of its parent, with specific local anchors.
    /// Values are pixels to move away from the parent.
    /// </summary>
    /// <param name="sprite"></param>
    /// <param name="pixelsFromBottom">Pixels from bottom - positive values places the sprite closer to the top</param>
    /// <param name="pixelsFromLeft">Pixels from left - positive values places the sprite closer to the right</param>
    /// <param name="yAnchor">Sprite vertical anchor</param>
    /// <param name="xAnchor">Sprite horizontal anchor</param>
    public static void pixelsFromBottomLeft(this IPositionable sprite, int pixelsFromBottom, int pixelsFromLeft, UIyAnchor yAnchor, UIxAnchor xAnchor)
    {
        // Update anchor information
        UIAnchorInfo anchorInfo = sprite.anchorInfo;
        anchorInfo.ParentUIxAnchor = UIxAnchor.Left;
        anchorInfo.ParentUIyAnchor = UIyAnchor.Bottom;
        anchorInfo.UIxAnchor = xAnchor;
        anchorInfo.UIyAnchor = yAnchor;
        anchorInfo.OffsetX = pixelsFromLeft;
        anchorInfo.OffsetY = pixelsFromBottom;
        anchorInfo.UIPrecision = UIPrecision.Pixel;

        // Set new anchor information
        sprite.anchorInfo = anchorInfo;

        // Refresh position
        sprite.refreshPosition();
    }
Esempio n. 18
0
    /// <summary>
    /// Finds horizontal adjustment for anchor, based on width and origin of sprite.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="width">Sprite width</param>
    /// <param name="originAnchor">Sprite origin anchor</param>
    /// <returns></returns>
    public static float xAnchorAdjustment( UIxAnchor anchor, float width, UIxAnchor originAnchor )
    {
        var adjustment = 0f;
        switch( anchor )
        {
            case UIxAnchor.Left:
                if (originAnchor == UIxAnchor.Center)
                {
                    adjustment -= width / 2f;
                }
                else if (originAnchor == UIxAnchor.Right)
                {
                    adjustment -= width;
                }
                break;
            case UIxAnchor.Right:
                if (originAnchor == UIxAnchor.Left)
                {
                    adjustment += width;
                }
                else if (originAnchor == UIxAnchor.Center)
                {
                    adjustment += width / 2f;
                }
                break;
            case UIxAnchor.Center:
                if (originAnchor == UIxAnchor.Left)
                {
                    adjustment += width / 2f;
                }
                else if (originAnchor == UIxAnchor.Right)
                {
                    adjustment -= width / 2f;
                }
                break;
        }

        return adjustment;
    }
 /// <summary>
 /// Calculates relative offset based on parent sprite width percentage.
 /// </summary>
 /// <param name="sprite">Provided parent ( or null for screen )</param>
 /// <param name="anchor">Sprite horizontal anchor</param>
 /// <param name="percentOffset">Percentage offset - 1 is 100%</param>
 /// <returns></returns>
 private static float xPercentFromParent( IPositionable sprite, UIxAnchor anchor, float percentOffset )
 {
     if ( percentOffset == 0)
         return 0;
     float offset = parentWidth( sprite ) * percentOffset;
     return ( anchor == UIxAnchor.Right ) ? -offset : offset;
 }
    /// <summary>
    /// Calculates horizontal pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float xPixelsFrom( UIxAnchor anchor, float pixelOffset )
    {
        // Get initial offset
        float offset = pixelOffset * UI.scaleFactor;
		
        // If anchor is right the offset is flipped
        if( anchor == UIxAnchor.Right )
        {
            offset = -offset;
        }
        return offset;
    }
Esempio n. 21
0
    /// <summary>
    /// Calculates fixed horizontal pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float xPixelsTo( UIxAnchor anchor, float offset )
    {
        // Get initial fixed offset
        float pixelOffset = offset / pixelDensityMultiplier();
		
        // If anchor is right the fixed offset is flipped
        if( anchor == UIxAnchor.Right )
        {
            pixelOffset = -pixelOffset;
        }
        return pixelOffset;
    }
Esempio n. 22
0
    /// <summary>
    /// Calculates horizontal pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float xPixelsFrom( UIxAnchor anchor, float pixelOffset )
    {
        // Get initial offset
        float offset = pixelOffset * pixelDensityMultiplier();
		
        // If anchor is right the offset is flipped
        if( anchor == UIxAnchor.Right )
        {
            offset = -offset;
        }
        return offset;
    }
    /// <summary>
    /// Calculates fixed horizontal pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite horizontal anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float xPixelsTo( UIxAnchor anchor, float offset )
    {
        // Get initial fixed offset
        float pixelOffset = offset / UI.scaleFactor;
		
        // If anchor is right the fixed offset is flipped
        if( anchor == UIxAnchor.Right )
        {
            pixelOffset = -pixelOffset;
        }
        return pixelOffset;
    }
Esempio n. 24
0
 /// <summary>
 /// Pixels to offset from the anchor.  If the anchor is right, the width will be used to make the offset
 /// from the right-most point of the sprite.
 /// </summary>
 public static float xPixelsFrom( UIxAnchor anchor, int pixelOffset )
 {
     return xPixelsFrom( anchor, pixelOffset, 0 );
 }
    /// <summary>
    /// Positions a sprite relatively to the top-left corner of its parent, with specific local anchors.
    /// Values are percentage of screen width/height to move away from the parent.
    /// </summary>
    /// <param name="sprite"></param>
    /// <param name="percentFromTop">Percentage from top - positive values places the sprite closer to the bottom</param>
    /// <param name="percentFromLeft">Percentage from left - positive values places the sprite closer to the right</param>
    /// <param name="yAnchor">Sprite vertical anchor</param>
    /// <param name="xAnchor">Sprite horizontal anchor</param>
    public static void positionFromTopLeft(this IPositionable sprite, float percentFromTop, float percentFromLeft, UIyAnchor yAnchor, UIxAnchor xAnchor)
    {
        // Update anchor information
        UIAnchorInfo anchorInfo = sprite.anchorInfo;

        anchorInfo.ParentUIxAnchor = UIxAnchor.Left;
        anchorInfo.ParentUIyAnchor = UIyAnchor.Top;
        anchorInfo.UIxAnchor       = xAnchor;
        anchorInfo.UIyAnchor       = yAnchor;
        anchorInfo.OffsetX         = percentFromLeft;
        anchorInfo.OffsetY         = percentFromTop;
        anchorInfo.UIPrecision     = UIPrecision.Percentage;

        // Set new anchor information
        sprite.anchorInfo = anchorInfo;

        // Refresh position
        sprite.refreshPosition();
    }
Esempio n. 26
0
 /// <summary>
 /// Percent to offset from the anchor.  If the anchor is right, the width will be used to make the offset
 /// from the right-most point of the sprite.
 /// </summary>
 public static float xPercentFrom( UIxAnchor anchor, float percentOffset )
 {
     return xPercentFrom( anchor, percentOffset, 0 );
 }
    /// <summary>
    /// Positions a sprite relatively to the center-right of its parent, with specific local anchors.
    /// Values are pixels to move away from the parent.
    /// </summary>
    /// <param name="sprite"></param>
    /// <param name="pixelsFromTop">Pixels from top - positive values places the sprite closer to the bottom</param>
    /// <param name="pixelsFromRight">Pixels from right - positive values places the sprite closer to the left</param>
    /// <param name="yAnchor">Sprite vertical anchor</param>
    /// <param name="xAnchor">Sprite horizontal anchor</param>
    public static void pixelsFromRight(this IPositionable sprite, int pixelsFromTop, int pixelsFromRight, UIyAnchor yAnchor, UIxAnchor xAnchor)
    {
        // Update anchor information
        UIAnchorInfo anchorInfo = sprite.anchorInfo;

        anchorInfo.ParentUIxAnchor = UIxAnchor.Right;
        anchorInfo.ParentUIyAnchor = UIyAnchor.Center;
        anchorInfo.UIxAnchor       = xAnchor;
        anchorInfo.UIyAnchor       = yAnchor;
        anchorInfo.OffsetX         = pixelsFromRight;
        anchorInfo.OffsetY         = pixelsFromTop;
        anchorInfo.UIPrecision     = UIPrecision.Pixel;

        // Set new anchor information
        sprite.anchorInfo = anchorInfo;

        // Refresh position
        sprite.refreshPosition();
    }
    /// <summary>
    /// Returns anchor position for a given parent and fallback to Screen if parent is null.
    /// </summary>
    /// <param name="sprite">Provided parent</param>
    /// <param name="yAnchor">Vertical anchor</param>
    /// <param name="xAnchor">Horizontal anchor</param>
    /// <returns>Adjusted anchor position</returns>
    private static Vector3 parentAnchorPosition( IPositionable sprite, UIyAnchor yAnchor, UIxAnchor xAnchor )
    {
        Vector3 position;
        float width, height;
        UIxAnchor originUIxAnchor = UIxAnchor.Left;
        UIyAnchor originUIyAnchor = UIyAnchor.Top;
        // Determine correct parent values
        if (sprite == null)
        {
            position = Vector3.zero;
            width = Screen.width;
            height = Screen.height;
        }
        else
        {
            position = sprite.position;
            width = sprite.width;
            height = sprite.height;
            originUIxAnchor = sprite.anchorInfo.OriginUIxAnchor;
            originUIyAnchor = sprite.anchorInfo.OriginUIyAnchor;
        }

        // Adjust anchor offset
        position.x += UIRelative.xAnchorAdjustment(xAnchor, width, originUIxAnchor);
        position.y -= UIRelative.yAnchorAdjustment(yAnchor, height, originUIyAnchor);

        return position;
    }