From e0985495844344673680e603927e12ec2f4f17ac Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 21 Aug 2015 12:03:43 +0100 Subject: [PATCH] User can click to skip current line of text. --- Assets/Fungus/UI/Scripts/Writer.cs | 34 +++++++++++-------- .../Sherlock/TheExperiment.unity | 2 +- Assets/Tests/UI/FakeWriterInput.cs | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Assets/Fungus/UI/Scripts/Writer.cs b/Assets/Fungus/UI/Scripts/Writer.cs index 3640de59..01b90032 100644 --- a/Assets/Fungus/UI/Scripts/Writer.cs +++ b/Assets/Fungus/UI/Scripts/Writer.cs @@ -397,17 +397,15 @@ namespace Fungus } } break; - } - inputFlag = false; - if (exit) { break; } } + inputFlag = false; isWriting = false; if (onComplete != null) @@ -432,6 +430,12 @@ namespace Fungus PartitionString(writeWholeWords, param, i, out left, out right); text = ConcatenateString(startText, openText, closeText, left, right); + // No delay if user has clicked + if (inputFlag) + { + continue; + } + // Punctuation pause if (left.Length > 0 && IsPunctuation(left.Substring(left.Length - 1)[0])) @@ -496,11 +500,6 @@ namespace Fungus return tempText; } - public virtual void SetInputFlag() - { - inputFlag = true; - } - public virtual string GetTagHelp() { return ""; @@ -513,21 +512,28 @@ namespace Fungus { duration = 1f; } - - yield return new WaitForSeconds(duration); + + float timeRemaining = duration; + while (timeRemaining > 0f && !inputFlag) + { + timeRemaining -= Time.deltaTime; + yield return null; + } } protected virtual IEnumerator DoWaitForInput(bool clear) { + inputFlag = false; isWaitingForInput = true; + while (!inputFlag) { yield return null; } - isWaitingForInput = false; - + + isWaitingForInput = false; inputFlag = false; - + if (clear) { textUI.text = ""; @@ -576,7 +582,7 @@ namespace Fungus // public virtual void OnNextLineEvent() { - SetInputFlag(); + inputFlag = true; } } diff --git a/Assets/FungusExamples/Sherlock/TheExperiment.unity b/Assets/FungusExamples/Sherlock/TheExperiment.unity index e71bdfb3..6b96d912 100644 --- a/Assets/FungusExamples/Sherlock/TheExperiment.unity +++ b/Assets/FungusExamples/Sherlock/TheExperiment.unity @@ -2594,7 +2594,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: targetTextObject: {fileID: 1116800860} - writingSpeed: 60 + writingSpeed: 10 punctuationPause: .25 hiddenTextColor: {r: 1, g: 1, b: 1, a: 0} writeWholeWords: 0 diff --git a/Assets/Tests/UI/FakeWriterInput.cs b/Assets/Tests/UI/FakeWriterInput.cs index 32b863e6..1af30265 100644 --- a/Assets/Tests/UI/FakeWriterInput.cs +++ b/Assets/Tests/UI/FakeWriterInput.cs @@ -16,7 +16,7 @@ namespace Fungus void DoFakeInput() { Writer writer = GetComponent(); - writer.SetInputFlag(); + writer.OnNextLineEvent(); } }