Esempio n. 1
0
 public void OnEnable()
 {
     layoutPosition                 = new LayoutPosition();
     layoutPosition.screen          = layoutScreen;
     layoutPosition.alignHorizontal = layoutAlignHorizontal;
     layoutPosition.alignVertical   = layoutAlignVertical;
     UI.Core.instance.layoutSystem.addWidget(this);
 }
Esempio n. 2
0
        public void setWidgetPosition(Widget widget, LayoutPosition newPosition)
        {
            if (!widgets.Contains(widget))
            {
                return;
            }
            RectTransform widgetRect = widget.GetComponent <RectTransform> ();

            Rect parentRect;

            if (newPosition.screen == Screen.left)
            {
                parentRect = leftScreen;
            }
            else if (newPosition.screen == Screen.right)
            {
                parentRect = rightScreen;
            }
            else
            {
                parentRect = centerScreen;
            }

            Vector2 newPos  = new Vector2();
            Vector2 newSize = new Vector2();

            if (newPosition.alignHorizontal == AlignmentH.stretch)
            {
                newPos.x  = parentRect.center.x;
                newSize.x = parentRect.width;
            }
            else if (newPosition.alignHorizontal == AlignmentH.left)
            {
                newPos.x  = parentRect.min.x + widgetRect.rect.width * 0.5f;
                newSize.x = widgetRect.rect.width;
            }
            else if (newPosition.alignHorizontal == AlignmentH.right)
            {
                newPos.x  = parentRect.max.x - widgetRect.rect.width * 0.5f;
                newSize.x = widgetRect.rect.width;
            }
            else
            {
                newPos.x  = parentRect.center.x;
                newSize.x = widgetRect.rect.width;
            }
            if (newPosition.alignVertical == AlignmentV.stretch)
            {
                newPos.y  = parentRect.center.y;
                newSize.y = parentRect.height;
            }
            else if (newPosition.alignVertical == AlignmentV.bottom)
            {
                newPos.y  = parentRect.min.y + widgetRect.rect.height * 0.5f;
                newSize.y = widgetRect.rect.height;
            }
            else if (newPosition.alignVertical == AlignmentV.top)
            {
                newPos.y  = parentRect.max.y - widgetRect.rect.height * 0.5f;
                newSize.y = widgetRect.rect.height;
            }
            else
            {
                newPos.y  = parentRect.center.y;
                newSize.y = widgetRect.rect.height;
            }

            //widgetRect.rect = new Rect (newPos, newSize);
            widgetRect.anchoredPosition = newPos;
            widgetRect.sizeDelta        = newSize;

            // Handle highlighting if the widget was placed onto the active screen:
            if (newPosition.screen == activeScreen)
            {
                widget.highlight();
            }
            else
            {
                widget.unHighlight();
            }
        }
Esempio n. 3
0
 public void setPosition(LayoutPosition newPosition)
 {
     layoutPosition = newPosition;
     UI.Core.instance.layoutSystem.setWidgetPosition(this, newPosition);
 }