/// <summary> /// Writes text using a typewriter effect to a UI text object. /// </summary> /// <param name="content">Text to be written</param> /// <param name="clear">If true clears the previous text.</param> /// <param name="waitForInput">Writes the text and then waits for player input before calling onComplete.</param> /// <param name="stopAudio">Stops any currently playing audioclip.</param> /// <param name="waitForVO">Wait for the Voice over to complete before proceeding</param> /// <param name="audioClip">Audio clip to play when text starts writing.</param> /// <param name="onComplete">Callback to call when writing is finished.</param> public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, bool waitForVO, AudioClip audioClip, System.Action onComplete) { if (clear) { textAdapter.Text = ""; visibleCharacterCount = 0; } if (!textAdapter.HasTextObject()) { yield break; } // If this clip is null then WriterAudio will play the default sound effect (if any) NotifyStart(audioClip); string tokenText = TextVariationHandler.SelectVariations(content); if (waitForInput) { tokenText += "{wi}"; } if (waitForVO) { tokenText += "{wvo}"; } List <TextTagToken> tokens = TextTagParser.Tokenize(tokenText); gameObject.SetActive(true); yield return(StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete))); }
/// <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); }
public override void OnEnter() { if (stringVariable == null) { Continue(); return; } TextAdapter textAdapter = new TextAdapter(); textAdapter.InitFromGameObject(targetTextObject); if (textAdapter.HasTextObject()) { stringVariable.Value = textAdapter.Text; } Continue(); }
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(); }
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; } } }
/// <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); }