예제 #1
0
        /// <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);
            }

            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;
            if (interactable && autoSelectFirstButton && !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
            {
                EventSystem.current.SetSelectedGameObject(button.gameObject);
            }
            Text textComponent = button.GetComponentInChildren <Text>();

            if (textComponent != null)
            {
                text = TextVariationHandler.SelectVariations(text);

                textComponent.text = text;
            }

            /*
             * currently commented out in order to prevent potential game crashes
             * if (button.gameObject.GetComponent<FungusBtnExtend>()) {
             *  button.gameObject.GetComponent<FungusBtnExtend>().onButtonPressed.AddListener(action);
             * } else { */
            button.onClick.AddListener(action);
            //}

            return(true);
        }
예제 #2
0
        /// <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)
            {
                Debug.LogWarning("Unable to add menu item, not enough buttons: " + text);
                return(false);
            }
            //if first option notify that a menu has started
            if (nextOptionIndex == 0)
            {
                MenuSignals.DoMenuStart(this);
            }

            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;
            if (interactable && autoSelectFirstButton && !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
            {
                EventSystem.current.SetSelectedGameObject(button.gameObject);
            }

            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);
        }
예제 #3
0
        /// <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);
            }

            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;
            if (interactable && autoSelectFirstButton && !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
            {
                EventSystem.current.SetSelectedGameObject(button.gameObject);
            }
            Text textComponent = button.GetComponentInChildren <Text>();

            if (textComponent != null)
            {
                textComponent.text = text;
            }
            button.onClick.AddListener(action);

            return(true);
        }
예제 #4
0
        /// <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);
        }