/// <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);
    }
示例#7
0
    void Start()
    {
        // IMPORTANT: depth is 1 on top higher numbers on the bottom.  This means the lower the number is the closer it gets to the camera.
        var y          = UIRelative.yPercentFrom(UIyAnchor.Top, .05f);
        var playButton = UIButton.create("playUp.png", "playDown.png", 0, (int)y);

        playButton.highlightedTouchOffsets = new UIEdgeOffsets(30);
        playButton.onTouchUpInside        += (sender) => Debug.Log("clicked the button: " + sender);


        // Scores button
        var scores = UIContinuousButton.create("scoresUp.png", "scoresDown.png", 0, 0);

        scores.positionFromTopLeft(.24f, .02f);
        scores.centerize();         // centerize the button so we can scale it from the center
        scores.highlightedTouchOffsets = new UIEdgeOffsets(30);
        scores.onTouchUpInside        += onTouchUpInsideScoresButton;
        scores.onTouchIsDown          += (sender) => Debug.Log("touch is down: " + Time.time);
        scores.touchDownSound          = scoresSound;


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

        optionsButton.positionFromTopLeft(.43f, .02f);
        optionsButton.onTouchUpInside += onTouchUpInsideOptionsButton;
        optionsButton.touchDownSound   = optionsSound;


        // Knob
        var knob = UIKnob.create("knobUp.png", "knobDown.png", 0, 0);

        knob.positionFromTopLeft(.39f, .5f);
        knob.normalTouchOffsets      = new UIEdgeOffsets(10);      // give the knob a bit extra touch area
        knob.highlightedTouchOffsets = new UIEdgeOffsets(30);
        knob.onKnobChanged          += onKnobChanged;
        knob.value = 0.3f;


        // Horizontal Slider
        var hSlider = UISlider.create("sliderKnob.png", "hSlider.png", 0, 0, UISliderLayout.Horizontal);

        hSlider.positionFromTopLeft(.7f, .02f);
        hSlider.highlightedTouchOffsets = new UIEdgeOffsets(30, 20, 30, 20);
        hSlider.onChange += (sender, val) => Debug.Log(val);
        hSlider.value     = 0.6f;


        // Vertical Slider
        var vSlider = UISlider.create("vSliderKnob.png", "vSlider.png", 0, 0, UISliderLayout.Vertical);

        vSlider.positionFromTopRight(.17f, .05f);
        vSlider.highlightedTouchOffsets = new UIEdgeOffsets(20, 30, 20, 30);
        vSlider.continuous = true;
        vSlider.onChange  += (sender, val) => Debug.Log(val);
        vSlider.value      = 0.3f;


        // Toggle Button
        var toggleButton = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);

        toggleButton.positionFromTopRight(.3f, .2f);
        toggleButton.onToggle += (sender, newValue) => hSlider.hidden = !newValue;
        toggleButton.selected  = true;


        // Progress/Health bar
        var progressBar = UIProgressBar.create("progressBar.png", "progressBarBorder.png", 5, 3, 0, 0);

        progressBar.positionFromBottomLeft(.05f, .02f);
        progressBar.resizeTextureOnChange = true;
        progressBar.value = 0.4f;


        // animated sprite
        var animatedSprite = UI.firstToolkit.addSprite("Gai_1.png", 0, 0, 1);
        var anim           = animatedSprite.addSpriteAnimation("anim", 0.15f, "Gai_1.png", "Gai_2.png", "Gai_3.png", "Gai_4.png", "Gai_5.png", "Gai_6.png", "Gai_7.png", "Gai_8.png", "Gai_9.png", "Gai_10.png", "Gai_11.png", "Gai_12.png");

        animatedSprite.positionFromBottomRight(.0f, .25f);
        anim.loopReverse = true;         // optinally loop in reverse
        animatedSprite.playSpriteAnimation("anim", 5);


        // Test movement
        StartCoroutine(marqueePlayButton(playButton));
        StartCoroutine(animateProgressBar(progressBar));
        StartCoroutine(pulseOptionButton(optionsButton));


        // UIObjects can be used like panels to group other UIObjects
        var panel = new UIObject();

        scores.parentUIObject        = panel;
        optionsButton.parentUIObject = panel;

        StartCoroutine(animatePanel(panel));
    }