Ejemplo n.º 1
0
        public override void Show()
        {
            base.Show();

            if (m_ButtonGroupController == null)
            {
                return;
            }

            m_ButtonGroupController.InstantiateButtonGroup();

            ButtonGroupData   buttonGroupData = m_ButtonGroupController.GetButtonGroupData();
            ButtonGroupVisual buttonGroup     = m_ButtonGroupController.GetButtonGroupVisual();

            if (m_IconButton != null && m_IconButton.image != null && buttonGroupData != null)
            {
                m_IconButton.image.sprite = buttonGroupData.image;
                m_IconButton.image.color  = buttonGroupData.color;
            }

            if (buttonGroup != null)
            {
                Button specialButton = buttonGroup.specialButton != null ? buttonGroup.specialButton.button : null;

                if (specialButton != null)
                {
                    if (m_IconButton != null && specialButton != null)
                    {
                        m_IconButton.interactable = specialButton.interactable;
                        m_IconButton.onClick.RemoveAllListeners();
                        m_IconButton.onClick.AddListener(() => specialButton.onClick.Invoke());
                    }

                    if (buttonGroup.specialButton is ButtonRV buttonRV)
                    {
                        buttonRV.OnRVLoaded    += OnRVLoaded;
                        buttonRV.OnRVCompleted += OnRewardedVideoCompleted;
                    }

                    buttonGroup.SpecialButtonDelayEnded.AddListener(OnSpecialButtonDelayEnded);

                    TextMeshProUGUI textMeshProUGUI =
                        buttonGroup.specialButton.GetComponentInChildren <TextMeshProUGUI>(true);
                    if (textMeshProUGUI)
                    {
                        textMeshProUGUI.text = buttonGroupData.text;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert ButtonGroup GameData into a GameObject in the store.
        /// Uses the Factory methods to load the button group.
        /// </summary>
        private ButtonGroup CreateButtonGroup(ButtonGroupData buttonGroup, UIConfig config)
        {
            Transform menuTransform = null;
            Color     background    = Color.white;
            Color     selected      = Color.white;
            Color     accent        = Color.white;
            bool      active        = true;

            if (buttonGroup is MainButtonGroupData)
            {
                menuTransform = MainMenu.transform;
                background    = config.MainMenuBackgroundColor;
                selected      = config.MainMenuSelectedColor;
                accent        = config.MainMenuAccentColor;
                active        = true;
            }
            else if (buttonGroup is SubButtonGroupData)
            {
                menuTransform = SubMenu.transform;
                background    = config.SubMenuBackgroundColor;
                selected      = config.SubMenuSelectedColor;
                accent        = config.SubMenuAccentColor;
                active        = false;
            }

            var buttonGroupObject = UIFactory.GenerateButtonGroup(
                menuTransform,
                new ButtonGroupArgs()
            {
                Name                  = buttonGroup.Name,
                ArrowLeft             = config.ArrowLeftSprite,
                ArrowRight            = config.ArrowRightSprite,
                Height                = MainMenu.GetComponent <RectTransform>().rect.height,
                PosY                  = 0,
                Left                  = config.HorizontalMargins,
                Right                 = config.HorizontalMargins,
                ButtonSize            = new Vector2(config.ButtonWidth, config.ButtonHeight),
                ButtonsDefaultColor   = background,
                ButtonsMouseOverColor = accent,
                ButtonsSelectedColor  = selected,
                Buttons               = CreateButtonArgs(buttonGroup.Buttons, config)
            });

            buttonGroupObject.SetActive(active);

            return(buttonGroupObject.GetComponent <ButtonGroup>());
        }