private void InitializeButtons()
        {
            buttons.Clear();

            foreach (Transform child in buttonParent)
            {
                AppBarButton appBarButton = child.GetComponent <AppBarButton>();
                if (appBarButton == null)
                {
                    throw new Exception("Found a transform without an AppBarButton component under buttonTransforms!");
                }

                appBarButton.InitializeButtonContent(this);
                // Set to invisible initially if not custom
                switch (appBarButton.ButtonType)
                {
                case ButtonTypeEnum.Custom:
                    break;

                default:
                    appBarButton.SetVisible(false);
                    break;
                }

                buttons.Add(appBarButton);
            }
        }
        private void UpdateButtons()
        {
            // First just count how many buttons are visible
            int activeButtonNum = 0;

            for (int i = 0; i < buttons.Count; i++)
            {
                AppBarButton button = buttons[i];

                switch (button.ButtonType)
                {
                case ButtonTypeEnum.Custom:
                    break;

                default:
                    button.SetVisible(GetButtonVisible(button.ButtonType));
                    break;
                }

                if (!buttons[i].Visible)
                {
                    continue;
                }

                activeButtonNum++;
            }

            // Sort the buttons by display order
            buttons.Sort(delegate(AppBarButton b1, AppBarButton b2) { return(b2.DisplayOrder.CompareTo(b1.DisplayOrder)); });

            // Use active button number to determine background size and offset
            float   backgroundBarSize = buttonWidth * activeButtonNum;
            Vector3 positionOffset    = Vector3.right * ((backgroundBarSize / 2) - (buttonWidth / 2));

            // Go through them again, setting active as
            activeButtonNum = 0;
            for (int i = 0; i < buttons.Count; i++)
            {
                // Set the sibling index and target position so the button will behave predictably when set visible
                buttons[i].transform.SetSiblingIndex(i);
                buttons[i].SetTargetPosition((Vector3.left * buttonWidth * activeButtonNum) + positionOffset);

                if (!buttons[i].Visible)
                {
                    continue;
                }

                activeButtonNum++;
            }

            targetBarSize.x = backgroundBarSize;
            backgroundBar.transform.localScale    = Vector3.Lerp(backgroundBar.transform.localScale, targetBarSize, Time.deltaTime * backgroundBarMoveSpeed);
            backgroundBar.transform.localPosition = Vector3.forward * buttonDepth / 2;
        }
Exemple #3
0
        private void InitializeButtons()
        {
            buttons.Clear();

            foreach (Transform child in buttonParent)
            {
                AppBarButton appBarButton = child.GetComponent <AppBarButton>();
                if (appBarButton == null)
                {
                    throw new Exception("Found a transform without an AppBarButton component under buttonTransforms!");
                }

                appBarButton.InitializeButtonContent(this);
                // Set to invisible initially
                appBarButton.SetVisible(false);

                buttons.Add(appBarButton);
            }
        }