コード例 #1
0
ファイル: MenuDialog.cs プロジェクト: zkitX/Grid_Fight
        /// <summary>
        /// Clear all displayed options in the Menu Dialog.
        /// </summary>
        public virtual void Clear()
        {
            StopAllCoroutines();

            //if something was shown notify that we are ending
            if (nextOptionIndex != 0)
            {
                MenuSignals.DoMenuEnd(this);
            }

            nextOptionIndex = 0;

            var optionButtons = CachedButtons;

            for (int i = 0; i < optionButtons.Length; i++)
            {
                var button = optionButtons[i];
                button.onClick.RemoveAllListeners();
            }

            for (int i = 0; i < optionButtons.Length; i++)
            {
                var button = optionButtons[i];
                if (button != null)
                {
                    button.transform.SetSiblingIndex(i);
                    button.gameObject.SetActive(false);
                }
            }

            Slider timeoutSlider = CachedSlider;

            if (timeoutSlider != null)
            {
                timeoutSlider.gameObject.SetActive(false);
            }
        }
コード例 #2
0
ファイル: MenuDialog.cs プロジェクト: 1194451658/fungus
        /// <summary>
        /// Adds the option to the list of displayed options. Calls a Block when selected.
        /// Will cause the Menu dialog to become visible if it is not already visible.
        /// </summary>
        /// <returns><c>true</c>, if the option was added successfully.</returns>
        /// <param name="text">The option text to display on the button.</param>
        /// <param name="interactable">If false, the option is displayed but is not selectable.</param>
        /// <param name="hideOption">If true, the option is not displayed but the menu knows that option can or did exist</param>
        /// <param name="action">Action attached to the button on the menu item</param>
        private bool AddOption(string text, bool interactable, bool hideOption, UnityEngine.Events.UnityAction action)
        {
            // 超出了
            // 搜索到的按钮的个数
            if (nextOptionIndex >= CachedButtons.Length)
            {
                return(false);
            }

            // 通知
            // 菜单开始显示了
            //if first option notify that a menu has started
            if (nextOptionIndex == 0)
            {
                MenuSignals.DoMenuStart(this);
            }

            // nextOptionIndex: 下一个将要使用的Button
            var button = cachedButtons[nextOptionIndex];

            //move forward for next call
            nextOptionIndex++;

            // 此菜单,
            // 是否是隐藏
            //don't need to set anything on it
            if (hideOption)
            {
                return(true);
            }

            // 显示菜单
            button.gameObject.SetActive(true);
            button.interactable = interactable;

            // Q: ???
            if (interactable &&
                autoSelectFirstButton &&
                !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
            {
                EventSystem.current.SetSelectedGameObject(button.gameObject);
            }

            // 使用TextAdapter
            // 设置按钮上的文本
            TextAdapter textAdapter = new TextAdapter();

            textAdapter.InitFromGameObject(button.gameObject, true);
            if (textAdapter.HasTextObject())
            {
                // 考虑文本变化
                text = TextVariationHandler.SelectVariations(text);

                textAdapter.Text = text;
            }

            // 监听按钮点击
            button.onClick.AddListener(action);

            return(true);
        }