Browse Source

Fixed: Concurrent Say calls cause Say Dialog to freeze up #156

Stop any previous Say call before executing the new one.
The Say Dialog Wait and Wait for Input methods now exit immediately if
the exit tag is set.
master
chrisgregan 10 years ago
parent
commit
e1ffa8aa2e
  1. 17
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  2. 13
      Assets/Fungus/UI/Scripts/Writer.cs
  3. 1609
      Assets/Tests/Narrative/NarrativeTests.unity

17
Assets/Fungus/Narrative/Scripts/SayDialog.cs

@ -131,6 +131,21 @@ namespace Fungus
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip audioClip, Action onComplete)
{
StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, audioClip, onComplete));
}
protected virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip audioClip, Action onComplete)
{
Writer writer = GetWriter();
// Stop any existing Say Command and write this one instead
// This will probably take a frame or two to complete
while (writer.isWriting || writer.isWaitingForInput)
{
writer.Stop();
yield return null;
}
this.fadeWhenDone = fadeWhenDone;
// Look for a character sound effect if no voice over clip is specified
@ -141,7 +156,7 @@ namespace Fungus
clip = speakingCharacter.soundEffect;
}
GetWriter().Write(text, clearPrevious, waitForInput, clip, onComplete);
writer.Write(text, clearPrevious, waitForInput, clip, onComplete);
}
protected virtual void LateUpdate()

13
Assets/Fungus/UI/Scripts/Writer.cs

@ -49,11 +49,15 @@ namespace Fungus
[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
/**
* This property is true when the writer is waiting for user input to continue
*/
[System.NonSerialized]
public bool isWaitingForInput;
// This property is true when the writer is writing text or waiting (i.e. still processing tokens)
/**
* This property is true when the writer is writing text or waiting (i.e. still processing tokens)
*/
[System.NonSerialized]
public bool isWriting;
@ -453,6 +457,7 @@ namespace Fungus
inputFlag = false;
exitFlag = false;
isWaitingForInput = false;
isWriting = false;
NotifyEnd();
@ -587,7 +592,7 @@ namespace Fungus
NotifyPause();
float timeRemaining = duration;
while (timeRemaining > 0f && !inputFlag)
while (timeRemaining > 0f && !inputFlag && !exitFlag)
{
timeRemaining -= Time.deltaTime;
yield return null;
@ -603,7 +608,7 @@ namespace Fungus
inputFlag = false;
isWaitingForInput = true;
while (!inputFlag)
while (!inputFlag && !exitFlag)
{
yield return null;
}

1609
Assets/Tests/Narrative/NarrativeTests.unity

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save