Esempio n. 1
0
        protected virtual void Awake()
        {
            GameObject go = targetTextObject;

            if (go == null)
            {
                go = gameObject;
            }

            textAdapter.InitFromGameObject(go);

            // Cache the list of child writer listeners
            var allComponents = GetComponentsInChildren <Component>();

            for (int i = 0; i < allComponents.Length; i++)
            {
                var             component      = allComponents[i];
                IWriterListener writerListener = component as IWriterListener;
                if (writerListener != null)
                {
                    writerListeners.Add(writerListener);
                }
            }

            CacheHiddenColorStrings();
        }
Esempio n. 2
0
        protected virtual void Awake()
        {
            if (showLog)
            {
                // Only one instance of NarrativeLogMenu may exist
                if (instance != null)
                {
                    Destroy(gameObject);
                    return;
                }

                instance = this;

                GameObject.DontDestroyOnLoad(this);

                clickAudioSource = GetComponent <AudioSource>();
            }
            else
            {
                GameObject logView = GameObject.Find("NarrativeLogView");
                logView.SetActive(false);
                this.enabled = false;
            }

            narLogViewtextAdapter.InitFromGameObject(narrativeLogView.gameObject, true);
        }
Esempio n. 3
0
        protected virtual void Awake()
        {
            if (!activeSayDialogs.Contains(this))
            {
                activeSayDialogs.Add(this);
            }

            nameTextAdapter.InitFromGameObject(nameText != null ? nameText.gameObject : nameTextGO);
            storyTextAdapter.InitFromGameObject(storyText != null ? storyText.gameObject : storyTextGO);
        }
Esempio n. 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)
            {
                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);
        }
Esempio n. 5
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();
        }
Esempio n. 6
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();
        }
Esempio n. 7
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;
                }
            }
        }
Esempio n. 8
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);
        }