/// <summary>
    /// Refreshes the sprite's position according to its anchor information.
    /// </summary>
    /// <param name="sprite"></param>
    public static void refreshPosition(this IPositionable sprite)
    {
        // Get sprite depth
        var depth = sprite.position.z;

        // Get anchor info
        var anchorInfo = sprite.anchorInfo;

        // Get parent anchor position
        var position = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor);

        // Add position offset
        if (anchorInfo.UIPrecision == UIPrecision.Percentage)
        {
            position.x += UIRelative.xPercentFrom(anchorInfo.UIxAnchor, parentWidth(anchorInfo.ParentUIObject), anchorInfo.OffsetX);
            position.y -= UIRelative.yPercentFrom(anchorInfo.UIyAnchor, parentHeight(anchorInfo.ParentUIObject), anchorInfo.OffsetY);
        }
        else
        {
            position.x += UIRelative.xPixelsFrom(anchorInfo.UIxAnchor, anchorInfo.OffsetX);
            position.y -= UIRelative.yPixelsFrom(anchorInfo.UIyAnchor, anchorInfo.OffsetY);
        }

        // Adjust for anchor offset
        position.x -= UIRelative.xAnchorAdjustment(anchorInfo.UIxAnchor, sprite.width, anchorInfo.OriginUIxAnchor);
        position.y += UIRelative.yAnchorAdjustment(anchorInfo.UIyAnchor, sprite.height, anchorInfo.OriginUIyAnchor);

        // Set depth
        position.z = depth;

        // Set new position
        sprite.position = position;
    }
Пример #2
0
    void Start()
    {
        int x = (int)UIRelative.xPercentFrom(UIxAnchor.Left, Screen.width, 0.5f);
        int y = (int)UIRelative.yPercentFrom(UIyAnchor.Top, Screen.height, 0.5f);

        sprite = UIToolkit.instance.addSprite("locking_blue.png", x, y, 40, true);

        Move(0, 0);
    }
Пример #3
0
    /// <summary>
    /// Positions a sprite relatively from the bottom-right corner of the screen.  Values are percentage of screen width/height to move away from the corner.
    /// The right boundary will be measured from the sprites right-most point
    /// The bottom boundary will be measured from the sprites bottom-most point
    /// </summary
    public static void positionFromBottomRight(this UISprite sprite, float percentFromBottom, float percentFromRight)
    {
        var pos = sprite.position;

        pos.x = UIRelative.xPercentFrom(UIxAnchor.Right, percentFromRight, sprite.width);
        pos.y = -UIRelative.yPercentFrom(UIyAnchor.Bottom, percentFromBottom, sprite.height);

        sprite.position = pos;
    }
Пример #4
0
    /// <summary>
    /// Positions a sprite relatively from the top-left corner of the screen.  Values are percentage of screen width/height to move away from the corner.
    /// </summary
    public static void positionFromTopLeft(this UISprite sprite, float percentFromTop, float percentFromLeft)
    {
        var pos = sprite.position;

        pos.x = UIRelative.xPercentFrom(UIxAnchor.Left, percentFromLeft);
        pos.y = -UIRelative.yPercentFrom(UIyAnchor.Top, percentFromTop);

        sprite.position = pos;
    }
Пример #5
0
    void Start()
    {
        // setup our text instance which will parse our .fnt file and allow us to
        var text = new UIText("prototype", "prototype.png");

        // spawn new text instances showing off the relative positioning features by placing one text instance in each corner
        var x = UIRelative.xPercentFrom(UIxAnchor.Left, 0f);
        var y = UIRelative.yPercentFrom(UIyAnchor.Top, 0f);

        text1 = text.addTextInstance("hello man.  I have a line\nbreak", x, y);


        var textSize = text.sizeForText("testing small bitmap fonts", 0.3f);

        x     = UIRelative.xPercentFrom(UIxAnchor.Left, 0f);
        y     = UIRelative.yPercentFrom(UIyAnchor.Bottom, 0f, textSize.y);
        text2 = text.addTextInstance("testing small bitmap fonts", x, y, 0.3f);


        textSize = text.sizeForText("with only\n1 draw call\nfor everything", 0.5f);
        x        = UIRelative.xPercentFrom(UIxAnchor.Right, 0f, textSize.x);
        y        = UIRelative.yPercentFrom(UIyAnchor.Top, 0f);
        text3    = text.addTextInstance("with only\n1 draw call\nfor everything", x, y, 0.5f, 5, Color.yellow);


        textSize = text.sizeForText("kudos");
        x        = UIRelative.xPercentFrom(UIxAnchor.Right, 0f, textSize.x);
        y        = UIRelative.yPercentFrom(UIyAnchor.Bottom, 0f, textSize.y);
        text4    = text.addTextInstance("kudos", x, y);


        textSize = text.sizeForText("Be sure to try this with\niPhone and iPad resolutions");
        var center = UIRelative.center(textSize.x, textSize.y);

        text.addTextInstance("Be sure to try this with\niPhone and iPad resolutions", center.x, center.y, 1f, 4, Color.red);

        StartCoroutine(waitThenRemoveText());
    }
Пример #6
0
    void Start()
    {
        // Scores button
        var scores = UIContinuousButton.create(buttonToolkit, "scoresUp.png", "scoresDown.png", 0, 0);

        scores.positionFromBottomRight(.02f, .02f);
        scores.highlightedTouchOffsets = new UIEdgeOffsets(30);


        // Options button
        var optionsButton = UIButton.create(buttonToolkit, "optionsUp.png", "optionsDown.png", 0, 0);

        optionsButton.positionFromBottomRight(.2f, .02f);


        // Text
        // setup our text instance which will parse our .fnt file and allow us to
        var text = new UIText(textToolkit, "prototype", "prototype.png");

        var x = UIRelative.xPercentFrom(UIxAnchor.Left, .05f);
        var y = UIRelative.yPercentFrom(UIyAnchor.Top, .1f);

        text.addTextInstance("hello man.  I have a line\nbreak", x, y);
    }