示例#1
0
 public UIButton()
 {
     Padding        = new UIAnchors(10, 10, 10, 10);
     Border         = new UIAnchors(1);
     LabelComponent = new UILabelComponent();
     AddComponent(LabelComponent);
 }
示例#2
0
    /// <summary>
    /// Rotates the button this script is attached to, so that it fits along the given anchor point.
    /// </summary>
    /// <param name="anchor"></param>
    private void RotateButton(UIAnchors anchor)
    {
        UIAnchors previousAnchor = this.anchor;

        this.anchor = anchor;

        if (anchor == UIAnchors.Right)
        {
            SetButtonRotation(90);
        }
        else if (anchor == UIAnchors.Left)
        {
            SetButtonRotation(-90);
        }
        else
        {
            SetButtonRotation(0);
        }

        AlignTabs(anchor);
        AlignTabs(previousAnchor);

        if (menuScript != null)
        {
            menuScript.Anchor = anchor;
        }
    }
示例#3
0
文件: TabMenu.cs 项目: dmaulikr/inkTD
    private void ChangeAnchor(UIAnchors anchor)
    {
        //TODO: Change the size of the menu or otherwise the menu used if anchor changes from left-right to top-bottom.
        this.anchor = anchor;
        switch (anchor)
        {
        case UIAnchors.Bottom:
            inwardGoal           = 0f;
            outwardGoal          = -topBottomRect.rect.height;
            leftRightOrientation = false;

            if (leftRightMenu != null)
            {
                leftRightMenu.SetActive(false);
            }
            if (topBottomMenu != null)
            {
                topBottomMenu.SetActive(true);
            }
            break;

        case UIAnchors.Left:
            inwardGoal           = leftRightRect.rect.width - Screen.width;
            outwardGoal          = -Screen.width;
            leftRightOrientation = true;

            if (leftRightMenu != null)
            {
                leftRightMenu.SetActive(true);
            }
            if (topBottomMenu != null)
            {
                topBottomMenu.SetActive(false);
            }
            break;

        case UIAnchors.Right:
            inwardGoal           = 0f;
            outwardGoal          = leftRightRect.rect.width;
            leftRightOrientation = true;

            if (leftRightMenu != null)
            {
                leftRightMenu.SetActive(true);
            }
            if (topBottomMenu != null)
            {
                topBottomMenu.SetActive(false);
            }
            break;

        case UIAnchors.Top:
            inwardGoal           = Screen.height - topBottomRect.rect.height;
            outwardGoal          = Screen.height - toolbar.rect.height;
            leftRightOrientation = false;

            if (leftRightMenu != null)
            {
                leftRightMenu.SetActive(false);
            }
            if (topBottomMenu != null)
            {
                topBottomMenu.SetActive(true);
            }
            break;
        }
        HideMenu();
    }
示例#4
0
    /// <summary>
    /// Aligns the positions of all the tabs along the given anchor point.
    /// </summary>
    /// <param name="anchor">The anchor point or side of the screen to align.</param>
    private void AlignTabs(UIAnchors anchor)
    {
        List <RectTransform> buttonsOnAnchor = new List <RectTransform>();

        for (int i = 0; i < buttons.Length; i++)
        {
            if (buttons[i].anchor == anchor)
            {
                buttonsOnAnchor.Add(buttonTransforms[i]);
            }
        }

        Vector3 alignmentPoint = Vector3.zero;

        if (anchor == UIAnchors.Right)
        {
            //The buttons are aligned via their bottom.
            alignmentPoint.x = canvasRect.rect.width - offsetRight;
            alignmentPoint.y = ScreenHeight / 2 + ((buttonsOnAnchor.Count - 1) * spaceBetweenButtons);
            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.y += t.rect.width / 2;
            }

            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.y -= spaceBetweenButtons + t.rect.width;
                t.position        = alignmentPoint;
            }
        }
        else if (anchor == UIAnchors.Left)
        {
            alignmentPoint.x = offsetLeft;
            alignmentPoint.y = ScreenHeight / 2 + ((buttonsOnAnchor.Count - 1) * spaceBetweenButtons);
            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.y += t.rect.width / 2;
            }

            foreach (RectTransform t in buttonsOnAnchor)
            {
                t.position        = alignmentPoint;
                alignmentPoint.y -= spaceBetweenButtons + t.rect.width;
            }
        }
        else if (anchor == UIAnchors.Top)
        {
            alignmentPoint.x = canvasRect.rect.width / 2 + ((buttonsOnAnchor.Count - 1) * spaceBetweenButtons);
            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.x += t.rect.width / 2;
            }

            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.y  = ScreenHeight - t.rect.height - offsetTop;
                alignmentPoint.x -= spaceBetweenButtons + t.rect.width;
                t.position        = alignmentPoint;
            }
        }
        else if (anchor == UIAnchors.Bottom)
        {
            alignmentPoint.y = offsetBottom;
            alignmentPoint.x = canvasRect.rect.width / 2 + ((buttonsOnAnchor.Count - 1) * spaceBetweenButtons);
            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.x += t.rect.width / 2;
            }

            foreach (RectTransform t in buttonsOnAnchor)
            {
                alignmentPoint.x -= spaceBetweenButtons + t.rect.width;
                t.position        = alignmentPoint;
            }
        }
    }