/// <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);
    }
Example #2
0
 /// <summary>
 /// Percent to offset from the anchor.  If the anchor is bottom, the height will be used to make the offset
 /// from the height-most point of the sprite.
 /// </summary>
 public static float yPercentFrom( UIyAnchor anchor, float percentOffset, float height = 0 )
 {
     switch( anchor )
     {
         case UIyAnchor.Top:
             return percentOffset * Screen.height;
         case UIyAnchor.Bottom:
             return Screen.height - ( percentOffset * Screen.height ) - height;
     }
     return 0f;
 }
Example #3
0
 /// <summary>
 /// Pixels to offset from the anchor.  If the anchor is bottom, the height will be used to make the offset
 /// from the bottom-most point of the sprite.
 /// </summary>
 public static float yPixelsFrom( UIyAnchor anchor, int pixelOffset, float height = 0 )
 {
     switch( anchor )
     {
         case UIyAnchor.Top:
             return pixelOffset;
         case UIyAnchor.Bottom:
             return Screen.height - pixelOffset - height;
     }
     return 0f;
 }
Example #4
0
    /// <summary>
    /// Calculates offset based on screen height percentage.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="height">Parent height</param>
    /// <param name="percentOffset">Percentage offset - 1 is 100%</param>
    /// <returns></returns>
    public static float yPercentFrom(UIyAnchor anchor, float height, float percentOffset)
    {
        // Get initial offset
        float offset = height * percentOffset;

        // If anchor is bottom the offset is flipped
        if (anchor == UIyAnchor.Bottom)
        {
            offset = -offset;
        }
        return(offset);
    }
Example #5
0
    /// <summary>
    /// Calculates vertical pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float yPixelsFrom(UIyAnchor anchor, float pixelOffset)
    {
        // Get initial offset
        float offset = pixelOffset * UI.scaleFactor;

        // If anchor is bottom the offset is flipped
        if (anchor == UIyAnchor.Bottom)
        {
            offset = -offset;
        }
        return(offset);
    }
Example #6
0
    /// <summary>
    /// Calculates fixed vertical pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float yPixelsTo(UIyAnchor anchor, float offset)
    {
        // Get initial fixed offset
        float pixelOffset = offset / pixelDensityMultiplier();

        // If anchor is bottom the fixed offset is flipped
        if (anchor == UIyAnchor.Bottom)
        {
            pixelOffset = -pixelOffset;
        }
        return(pixelOffset);
    }
Example #7
0
    /// <summary>
    /// Calculates vertical pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float yPixelsFrom(UIyAnchor anchor, float pixelOffset)
    {
        // Get initial offset
        float offset = pixelOffset * pixelDensityMultiplier();

        // If anchor is bottom the offset is flipped
        if (anchor == UIyAnchor.Bottom)
        {
            offset = -offset;
        }
        return(offset);
    }
Example #8
0
    /// <summary>
    /// Percent to offset from the anchor.  If the anchor is bottom, the height will be used to make the offset
    /// from the height-most point of the sprite.
    /// </summary>
    public static float yPercentFrom(UIyAnchor anchor, float percentOffset, float height = 0)
    {
        switch (anchor)
        {
        case UIyAnchor.Top:
            return(percentOffset * Screen.height);

        case UIyAnchor.Bottom:
            return(Screen.height - (percentOffset * Screen.height) - height);
        }
        return(0f);
    }
Example #9
0
    /// <summary>
    /// Pixels to offset from the anchor.  If the anchor is bottom, the height will be used to make the offset
    /// from the bottom-most point of the sprite.
    /// </summary>
    public static float yPixelsFrom(UIyAnchor anchor, int pixelOffset, float height = 0)
    {
        switch (anchor)
        {
        case UIyAnchor.Top:
            return(pixelOffset);

        case UIyAnchor.Bottom:
            return(Screen.height - pixelOffset - height);
        }
        return(0f);
    }
Example #10
0
    /// <summary>
    /// Calculates fixed vertical pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float yPixelsTo(UIyAnchor anchor, float offset)
    {
        // Get initial fixed offset
        float pixelOffset = offset / UI.scaleFactor;

        // If anchor is bottom the fixed offset is flipped
        if (anchor == UIyAnchor.Bottom)
        {
            pixelOffset = -pixelOffset;
        }
        return(pixelOffset);
    }
Example #11
0
    /// <summary>
    /// Calculates offset based on screen height percentage.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="height">Parent height</param>
    /// <param name="percentOffset">Percentage offset - 1 is 100%</param>
    /// <returns></returns>
    public static float yPercentFrom( UIyAnchor anchor, float height, float percentOffset )
    {
        // Get initial offset
        float offset = height * percentOffset;
		
        // If anchor is bottom the offset is flipped
        if( anchor == UIyAnchor.Bottom )
        {
            offset = -offset;
        }
        return offset;
    }
    /// <summary>
    /// Calculates screen height percentage based on offset.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="height">Parent height</param>
    /// <param name="offset">Position offset</param>
    /// <returns></returns>
    public static float yPercentTo( UIyAnchor anchor, float height, float offset )
    {
        if (height == 0f) return 0f;

        // Get initial percentage
        float percentOffset = offset / height;
		
        // If anchor is bottom the percentage is flipped
        if( anchor == UIyAnchor.Bottom )
        {
            percentOffset = -percentOffset;
        }
        return percentOffset;
    }
Example #13
0
    /// <summary>
    /// Calculates screen height percentage based on offset.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="height">Parent height</param>
    /// <param name="offset">Position offset</param>
    /// <returns></returns>
    public static float yPercentTo(UIyAnchor anchor, float height, float offset)
    {
        if (height == 0f)
        {
            return(0f);
        }

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

        // If anchor is bottom the percentage is flipped
        if (anchor == UIyAnchor.Bottom)
        {
            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();
    }
Example #16
0
    /// <summary>
    /// Finds vertical adjustment for anchor, based on height and origin of sprite.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="height">Sprite height</param>
    /// <param name="originAnchor">Sprite origin anchor</param>
    /// <returns></returns>
    public static float yAnchorAdjustment(UIyAnchor anchor, float height, UIyAnchor originAnchor)
    {
        float adjustment = 0f;

        switch (anchor)
        {
        case UIyAnchor.Top:
            if (originAnchor == UIyAnchor.Center)
            {
                adjustment -= height / 2f;
            }
            else if (originAnchor == UIyAnchor.Bottom)
            {
                adjustment -= height;
            }
            break;

        case UIyAnchor.Bottom:
            if (originAnchor == UIyAnchor.Top)
            {
                adjustment += height;
            }
            else if (originAnchor == UIyAnchor.Center)
            {
                adjustment += height / 2f;
            }
            break;

        case UIyAnchor.Center:
            if (originAnchor == UIyAnchor.Top)
            {
                adjustment += height / 2f;
            }
            else if (originAnchor == UIyAnchor.Bottom)
            {
                adjustment -= height / 2f;
            }
            break;
        }
        return(adjustment);
    }
 /// <summary>
 /// Calculates relative offset based on parent sprite height percentage.
 /// </summary>
 /// <param name="sprite">Provided parent ( or null for screen )</param>
 /// <param name="anchor">Sprite vertical anchor</param>
 /// <param name="percentOffset">Percentage offset - 1 is 100%</param>
 /// <returns></returns>
 private static float yPercentFromParent( IPositionable sprite, UIyAnchor anchor, float percentOffset )
 {
     if ( percentOffset == 0)
         return 0;
     float offset = parentHeight( sprite ) * percentOffset;
     return ( anchor == UIyAnchor.Bottom ) ? -offset : offset;
 }
Example #18
0
 /// <summary>
 /// Finds vertical adjustment for anchor, based on height and origin of sprite.
 /// </summary>
 /// <param name="anchor">Sprite vertical anchor</param>
 /// <param name="height">Sprite height</param>
 /// <param name="originAnchor">Sprite origin anchor</param>
 /// <returns></returns>
 public static float yAnchorAdjustment(UIyAnchor anchor, float height, UIyAnchor originAnchor)
 {
     float adjustment = 0f;
     switch( anchor )
     {
         case UIyAnchor.Top:
             if (originAnchor == UIyAnchor.Center)
             {
                 adjustment -= height / 2f;
             }
             else if (originAnchor == UIyAnchor.Bottom)
             {
                 adjustment -= height;
             }
             break;
         case UIyAnchor.Bottom:
             if (originAnchor == UIyAnchor.Top)
             {
                 adjustment += height;
             }
             else if (originAnchor == UIyAnchor.Center)
             {
                 adjustment += height / 2f;
             }
             break;
         case UIyAnchor.Center:
             if (originAnchor == UIyAnchor.Top)
             {
                 adjustment += height / 2f;
             }
             else if (originAnchor == UIyAnchor.Bottom)
             {
                 adjustment -= height / 2f;
             }
             break;
     }
     return adjustment;
 }
Example #19
0
    /// <summary>
    /// Calculates fixed vertical pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float yPixelsTo( UIyAnchor anchor, float offset )
    {
        // Get initial fixed offset
        float pixelOffset = offset / pixelDensityMultiplier();
		
        // If anchor is bottom the fixed offset is flipped
        if( anchor == UIyAnchor.Bottom )
        {
            pixelOffset = -pixelOffset;
        }
        return pixelOffset;
    }
Example #20
0
    /// <summary>
    /// Calculates vertical pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float yPixelsFrom( UIyAnchor anchor, float pixelOffset )
    {
        // Get initial offset
        float offset = pixelOffset * pixelDensityMultiplier();
		
        // If anchor is bottom the offset is flipped
        if( anchor == UIyAnchor.Bottom )
        {
            offset = -offset;
        }
        return offset;
    }
Example #21
0
 /// <summary>
 /// Percent to offset from the anchor.  If the anchor is bottom, the height will be used to make the offset
 /// from the height-most point of the sprite.
 /// </summary>
 public static float yPercentFrom( UIyAnchor anchor, float percentOffset )
 {
     return yPercentFrom( anchor, percentOffset, 0 );
 }
Example #22
0
 public static float yPixelsFrom( UIyAnchor anchor, int pixelOffset, float height )
 {
     switch( anchor )
     {
         case UIyAnchor.Top:
             return pixelOffset * pixelDensityMultiplier();
         case UIyAnchor.Bottom:
             return Screen.height - pixelOffset*pixelDensityMultiplier() - height;
     }
     return 0f;
 }
Example #23
0
 /// <summary>
 /// Pixels to offset from the anchor.  If the anchor is bottom, the height will be used to make the offset
 /// from the bottom-most point of the sprite.
 /// </summary>
 public static float yPixelsFrom( UIyAnchor anchor, int pixelOffset )
 {
     return yPixelsFrom( anchor, pixelOffset, 0 );
 }
    /// <summary>
    /// Calculates vertical pixel offset based on SD or HD.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="pixelOffset">Fixed offset</param>
    /// <returns></returns>
    public static float yPixelsFrom( UIyAnchor anchor, float pixelOffset )
    {
        // Get initial offset
        float offset = pixelOffset * UI.scaleFactor;
		
        // If anchor is bottom the offset is flipped
        if( anchor == UIyAnchor.Bottom )
        {
            offset = -offset;
        }
        return offset;
    }
    /// <summary>
    /// Calculates fixed vertical pixel offset based on SD or HD offset.
    /// </summary>
    /// <param name="anchor">Sprite vertical anchor</param>
    /// <param name="offset">Relative offset</param>
    /// <returns></returns>
    public static float yPixelsTo( UIyAnchor anchor, float offset )
    {
        // Get initial fixed offset
        float pixelOffset = offset / UI.scaleFactor;
		
        // If anchor is bottom the fixed offset is flipped
        if( anchor == UIyAnchor.Bottom )
        {
            pixelOffset = -pixelOffset;
        }
        return pixelOffset;
    }
    /// <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 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;
    }