Exemple #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)
            {
                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);
        }
Exemple #2
0
        public override void OnEnter()
        {
            if (stringVariable == null)
            {
                Continue();
                return;
            }

            TextAdapter textAdapter = new TextAdapter();

            textAdapter.InitFromGameObject(targetTextObject);

            if (textAdapter.HasTextObject())
            {
                stringVariable.Value = textAdapter.Text;
            }

            Continue();
        }
Exemple #3
0
        public override void OnEnter()
        {
            var    flowchart = GetFlowchart();
            string newText   = flowchart.SubstituteVariables(text.Value);

            if (targetTextObject == null)
            {
                Continue();
                return;
            }

            TextAdapter textAdapter = new TextAdapter();

            textAdapter.InitFromGameObject(targetTextObject);

            if (textAdapter.HasTextObject())
            {
                textAdapter.Text = newText;
            }

            Continue();
        }
Exemple #4
0
        public void UpdateCurrentLangContent(SystemLanguage language)
        {
            //initialize will call it , and in the time it's null
            if (cachedButtons == null)
            {
                return;
            }

            for (int i = 0; i < cachedButtons.Length; i++)
            {
                TextAdapter textAdapter = new TextAdapter();
                textAdapter.InitFromGameObject(cachedButtons[i].gameObject, true);
                if (textAdapter.HasTextObject() && !string.IsNullOrEmpty(_onScreenTextTerms[i]))
                {
                    string localText = LocalizeManager.GetLocalizeText(_onScreenTextTerms[i]);

                    if (string.IsNullOrEmpty(localText))
                    {
                        localText = $"no key:{_onScreenTextTerms[i]}";
                    }
                    else
                    {
                        //trim flowchart's token
                        if (_onScreenFlowchart != null)
                        {
                            localText = _onScreenFlowchart.SubstituteVariables(localText);
                        }

                        //trim global TextVariation's token
                        localText = TextVariationHandler.SelectVariations(localText);
                    }

                    textAdapter.Text = localText;
                }
            }
        }
Exemple #5
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);
        }