diff --git a/Assets/Fungus/Narrative/Scripts/SayDialog.cs b/Assets/Fungus/Narrative/Scripts/SayDialog.cs index 2dd57e81..0b359b9c 100644 --- a/Assets/Fungus/Narrative/Scripts/SayDialog.cs +++ b/Assets/Fungus/Narrative/Scripts/SayDialog.cs @@ -15,6 +15,8 @@ namespace Fungus public Image continueImage; public AudioClip continueSound; + protected Writer writer; + public static SayDialog GetSayDialog() { if (activeSayDialog == null) @@ -43,41 +45,38 @@ namespace Fungus return activeSayDialog; } - protected virtual void Start() + protected Writer GetWriter() { - CanvasGroup canvasGroup = dialogCanvas.GetComponent(); - canvasGroup.alpha = 0f; - } + if (writer != null) + { + return writer; + } - public virtual void Say(string text, bool clearPrevious, bool waitForInput, AudioClip voiceOverClip, Action onComplete) - { - Writer writer = GetComponent(); + writer = GetComponent(); if (writer == null) { writer = gameObject.AddComponent(); } - ShowContinueImage(false); - - writer.Write(text, clearPrevious, waitForInput, onComplete); + return writer; } - public override void Clear() + protected virtual void Start() { - base.Clear(); - ShowContinueImage(false); + CanvasGroup canvasGroup = dialogCanvas.GetComponent(); + canvasGroup.alpha = 0f; } - protected virtual void OnWaitForInputTag(bool waiting) + public virtual void Say(string text, bool clearPrevious, bool waitForInput, AudioClip voiceOverClip, Action onComplete) { - ShowContinueImage(waiting); + GetWriter().Write(text, clearPrevious, waitForInput, onComplete); } - protected virtual void ShowContinueImage(bool visible) + protected virtual void Update() { if (continueImage != null) { - continueImage.enabled = visible; + continueImage.enabled = GetWriter().isWaitingForInput; } } } diff --git a/Assets/Fungus/UI/Scripts/Writer.cs b/Assets/Fungus/UI/Scripts/Writer.cs index 055a1576..6c65a981 100644 --- a/Assets/Fungus/UI/Scripts/Writer.cs +++ b/Assets/Fungus/UI/Scripts/Writer.cs @@ -9,12 +9,25 @@ namespace Fungus public class Writer : MonoBehaviour, IDialogInputListener { + [Tooltip("Gameobject containing a Text, Inout Field or Text Mesh object to write to")] public GameObject targetTextObject; + + [Tooltip("Writing characters per second")] public float writingSpeed = 60; + + [Tooltip("Pause duration for punctuation characters")] public float punctuationPause = 0.25f; + + [Tooltip("Color of text that has not been revealed yet")] public Color hiddenTextColor = new Color(1,1,1,0); + + [Tooltip("Write one word at a time rather one character at a time")] public bool writeWholeWords = false; - + + // This property is true when the writer is waiting for user input to continue + [System.NonSerialized] + public bool isWaitingForInput; + protected float currentWritingSpeed; protected float currentPunctuationPause; protected Text textUI; @@ -498,10 +511,12 @@ namespace Fungus protected virtual IEnumerator DoWaitForInput(bool clear) { + isWaitingForInput = true; while (!inputFlag) { yield return null; } + isWaitingForInput = false; inputFlag = false;