예제 #1
0
        private void Awake()
        {
#if UNITY_EDITOR
            if (string.IsNullOrWhiteSpace(_menu))
            {
                Debug.LogError("You are trying to use tooltips, but without any menu. Please set the menu that should be used for tooltips.");
                return;
            }
#endif

            OnHover onHover = this.gameObject.AddComponent <OnHover>();
            onHover.Delay          = _tooltipDelay;
            onHover.onPointerDelay = () => {
                MCSimpleTooltipData simpleTooltipData = new MCSimpleTooltipData("Tooltip", _tooltipText,
                                                                                this.GetComponent <RectTransform>())
                {
                    AutoRemove = true
                };
                if (_menuController)
                {
                    _menuController.AddPopup(_menu, false, simpleTooltipData);
                }
                else
                {
                    MenuController.AddPopupGlobal(_menu, false, simpleTooltipData);
                }
            };
        }
예제 #2
0
        public override void Show(object data)
        {
            if (data == null)
            {
                throw new Exception("Trying to start a simple popup with a data that is equal to null!");
            }

            base.Show(data);

            MCSimplePopupData simplePopupData = data as MCSimplePopupData;

            if (simplePopupData == null)
            {
                throw new Exception("Trying to show a simple popup, but using the wrong data type: " + data.GetType());
            }

            bool hasButtons = simplePopupData.ButtonDatas != null && simplePopupData.ButtonDatas.Length > 0;

            _disableIfNoButtons.SetActive(hasButtons);
            for (int i = 0; i < simplePopupData.ButtonDatas.Length; i++)
            {
                Button newButton = Instantiate(_buttonPrefab, _buttonParent);
                newButton.onClick.RemoveAllListeners();
                MCButtonData buttonData = simplePopupData.ButtonDatas[i];
                if (buttonData.ButtonClick != null)
                {
                    newButton.onClick.AddListener(() => buttonData.ButtonClick(newButton));
                }

                // Use the icon if one is present, use text otherwise.
                if (buttonData.Icon != null)
                {
                    Image imageChild = newButton.GetComponentInChildren <Image>();
                    imageChild.sprite = buttonData.Icon;
                }
                else
                {
                    Text textChild = newButton.GetComponentInChildren <Text>();
                    textChild.text = buttonData.Text;
                }

                // Create the tooltip component and add the OnHover components to the object if it wants a tooltip.
                if (buttonData.Tooltip)
                {
                    MCSimpleTooltipData simpleTooltipData = new MCSimpleTooltipData("Tooltip", buttonData.TooltipText,
                                                                                    newButton.GetComponent <RectTransform>())
                    {
                        AutoRemove = true
                    };

                    OnHover onHover = newButton.GetComponent <OnHover>();
                    if (!onHover)
                    {
                        onHover = newButton.gameObject.AddComponent <OnHover>();
                    }
                    onHover.Delay           = 1;
                    onHover.onPointerDelay += () => {
                        this.MenuController.AddPopup("SIMPLETOOLTIP", false, simpleTooltipData);
                    };
                }

                newButton.gameObject.SetActive(true);
            }

            _buttonPrefab.gameObject.SetActive(false);

            gameObject.SetActive(true);
        }