Exemplo n.º 1
0
        private void ResetLayout()
        {
            foreach (KeyValuePair <string, UIButtonBarItem> pair in _buttons)
            {
                UIButtonBarItem barButton     = pair.Value;
                LayoutElement   layoutElement = barButton.GetComponent <LayoutElement> ();
                layoutElement.preferredWidth = -1;
            }

            RectTransform cRect = container.GetComponent <RectTransform> ();

            cRect.anchorMin = Vector2.zero;
            cRect.anchorMax = new Vector2(0, 1);
            cRect.sizeDelta = Vector2.zero;
            cRect.offsetMin = Vector2.zero;
            cRect.offsetMax = Vector2.zero;

            container.childForceExpandHeight = true;
            container.childForceExpandWidth  = false;
            container.spacing = 40;
            container.padding = new RectOffset(40, 40, 0, 0);

            _backgroundVLG.padding = new RectOffset(0, 0, 0, 0);

            container.GetComponent <ContentSizeFitter> ().horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            container.SetLayoutHorizontal();
        }
Exemplo n.º 2
0
        private bool _AddButton(UIButtonBarItemModel _item)
        {
            bool _added = false;

            if (!_buttons.ContainsKey(_item.data))
            {
                UIButtonBarItem _button = Instantiate(button);
                _button.gameObject.SetActive(true);
                _button.transform.SetParent(container.transform, false);
                _button.transform.localScale = Vector3.one;
                _button.SetData(_item, TabButtonPressed);
                _buttons.Add(_item.data, _button);
                _added = true;
            }
            return(_added);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Resets the buttons.
 /// </summary>
 public void ResetButtons()
 {
     _currentTabData = null;
     if (_buttons == null)
     {
         return;
     }
     foreach (KeyValuePair <string, UIButtonBarItem> pair in _buttons)
     {
         UIButtonBarItem button = pair.Value;
         if (button != null)
         {
             Destroy(button.gameObject);
         }
     }
     _buttons.Clear();
 }
Exemplo n.º 4
0
        private void TabButtonPressed(UIButtonBarItemModel data)
        {
            if (_currentTabData != null)
            {
                UIButtonBarItem currentButton = _buttons [_currentTabData.data];
                currentButton.SetInteractable(true);
            }

            _currentTabData = data;
            if (onBarItemPressed != null)
            {
                onBarItemPressed.Invoke(data);
            }

            UIButtonBarItem barButton = _buttons [data.data];

            barButton.SetInteractable(false);
        }
Exemplo n.º 5
0
        private void UpdateLayout()
        {
            Rect barSize       = transform.GetComponent <RectTransform> ().rect;
            Rect containerSize = container.GetComponent <RectTransform> ().rect;

            if (containerSize.width > barSize.width)
            {
                ResetLayout();
            }
            else
            {
                float elementSize = barSize.width / _buttons.Count;
                foreach (KeyValuePair <string, UIButtonBarItem> pair in _buttons)
                {
                    UIButtonBarItem barButton     = pair.Value;
                    LayoutElement   layoutElement = barButton.GetComponent <LayoutElement> ();
                    layoutElement.preferredWidth = elementSize;
                }

                RectTransform cRect = container.GetComponent <RectTransform> ();
                cRect.anchorMin = Vector2.zero;
                cRect.anchorMax = Vector2.one;
                cRect.sizeDelta = Vector2.zero;
                cRect.offsetMin = Vector2.zero;
                cRect.offsetMax = Vector2.zero;

                container.childForceExpandHeight = true;
                container.childForceExpandWidth  = true;
                container.spacing = 0;
                container.padding = new RectOffset(0, 0, 0, 0);

                _backgroundVLG.padding = new RectOffset(0, 0, 0, 0);

                container.GetComponent <ContentSizeFitter> ().horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
                container.SetLayoutHorizontal();
            }
        }