diff --git a/Assets/Fungus/Narrative/Editor/SayEditor.cs b/Assets/Fungus/Narrative/Editor/SayEditor.cs
index 273b50c9..11a9ecb8 100644
--- a/Assets/Fungus/Narrative/Editor/SayEditor.cs
+++ b/Assets/Fungus/Narrative/Editor/SayEditor.cs
@@ -80,6 +80,7 @@ namespace Fungus
protected SerializedProperty extendPreviousProp;
protected SerializedProperty fadeWhenDoneProp;
protected SerializedProperty waitForClickProp;
+ protected SerializedProperty stopVoiceoverProp;
protected SerializedProperty setSayDialogProp;
protected virtual void OnEnable()
@@ -97,6 +98,7 @@ namespace Fungus
extendPreviousProp = serializedObject.FindProperty("extendPrevious");
fadeWhenDoneProp = serializedObject.FindProperty("fadeWhenDone");
waitForClickProp = serializedObject.FindProperty("waitForClick");
+ stopVoiceoverProp = serializedObject.FindProperty("stopVoiceover");
setSayDialogProp = serializedObject.FindProperty("setSayDialog");
if (blackTex == null)
@@ -190,6 +192,7 @@ namespace Fungus
EditorGUILayout.PropertyField(fadeWhenDoneProp);
EditorGUILayout.PropertyField(waitForClickProp);
+ EditorGUILayout.PropertyField(stopVoiceoverProp);
EditorGUILayout.PropertyField(setSayDialogProp);
if (showPortraits && t.portrait != null)
diff --git a/Assets/Fungus/Narrative/Scripts/Commands/Say.cs b/Assets/Fungus/Narrative/Scripts/Commands/Say.cs
index dbb6de44..b0fde7f8 100644
--- a/Assets/Fungus/Narrative/Scripts/Commands/Say.cs
+++ b/Assets/Fungus/Narrative/Scripts/Commands/Say.cs
@@ -42,6 +42,9 @@ namespace Fungus
[Tooltip("Wait for player to click before continuing.")]
public bool waitForClick = true;
+ [Tooltip("Stop playing voiceover when text finishes writing.")]
+ public bool stopVoiceover = true;
+
[Tooltip("Sets the active Say dialog with a reference to a Say Dialog object in the scene. All story text will now display using this Say Dialog.")]
public SayDialog setSayDialog;
@@ -96,7 +99,7 @@ namespace Fungus
string subbedText = flowchart.SubstituteVariables(displayText);
- sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, voiceOverClip, delegate {
+ sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, voiceOverClip, stopVoiceover, delegate {
Continue();
});
}
diff --git a/Assets/Fungus/Narrative/Scripts/SayDialog.cs b/Assets/Fungus/Narrative/Scripts/SayDialog.cs
index 8c904670..3f3d8c90 100644
--- a/Assets/Fungus/Narrative/Scripts/SayDialog.cs
+++ b/Assets/Fungus/Narrative/Scripts/SayDialog.cs
@@ -126,12 +126,12 @@ namespace Fungus
}
}
- public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip voiceOverClip, Action onComplete)
+ public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip voiceOverClip, bool stopVoiceover, Action onComplete)
{
- StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, voiceOverClip, onComplete));
+ StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, voiceOverClip, stopVoiceover, onComplete));
}
- protected virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip voiceOverClip, Action onComplete)
+ protected virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip voiceOverClip, bool stopVoiceover, Action onComplete)
{
Writer writer = GetWriter();
@@ -158,7 +158,7 @@ namespace Fungus
{
soundEffectClip = speakingCharacter.soundEffect;
}
- writer.Write(text, clearPrevious, waitForInput, soundEffectClip, onComplete);
+ writer.Write(text, clearPrevious, waitForInput, stopVoiceover, soundEffectClip, onComplete);
}
diff --git a/Assets/Fungus/UI/Scripts/Commands/Write.cs b/Assets/Fungus/UI/Scripts/Commands/Write.cs
index 537d88f7..7e511976 100644
--- a/Assets/Fungus/UI/Scripts/Commands/Write.cs
+++ b/Assets/Fungus/UI/Scripts/Commands/Write.cs
@@ -86,12 +86,12 @@ namespace Fungus
if (!waitUntilFinished)
{
- writer.Write(newText, clearText, false, null, null);
+ writer.Write(newText, clearText, false, true, null, null);
Continue();
}
else
{
- writer.Write(newText, clearText, false, null,
+ writer.Write(newText, clearText, false, true, null,
() => { Continue (); }
);
}
diff --git a/Assets/Fungus/UI/Scripts/Writer.cs b/Assets/Fungus/UI/Scripts/Writer.cs
index ffeb722e..7289f8f6 100644
--- a/Assets/Fungus/UI/Scripts/Writer.cs
+++ b/Assets/Fungus/UI/Scripts/Writer.cs
@@ -13,23 +13,26 @@ namespace Fungus
*/
public interface IWriterListener
{
- // Called when a user input event (e.g. a click) has been handled by the Writer
+ ///
+ /// Called when a user input event (e.g. a click) has been handled by the Writer.
+ ///
void OnInput();
- // Called when the Writer starts writing new text
- // An optional audioClip sound effect can be supplied (e.g. for voiceover)
+ /// Called when the Writer starts writing new text
+ /// An optional audioClip sound effect can be supplied (e.g. for voiceover)
void OnStart(AudioClip audioClip);
- // Called when the Writer has paused writing text (e.g. on a {wi} tag)
+ /// Called when the Writer has paused writing text (e.g. on a {wi} tag).
void OnPause();
- // Called when the Writer has resumed writing text
+ /// Called when the Writer has resumed writing text.
void OnResume();
- // Called when the Writer has finshed writing text
- void OnEnd();
+ /// Called when the Writer has finshed writing text.
+ /// Controls whether audio should be stopped when writing ends.
+ void OnEnd(bool stopAudio);
- // Called every time the Writer writes a new character glyph
+ /// Called every time the Writer writes a new character glyph.
void OnGlyph();
}
@@ -314,7 +317,7 @@ namespace Fungus
}
}
- public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete)
+ public virtual void Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, Action onComplete)
{
if (clear)
{
@@ -338,7 +341,7 @@ namespace Fungus
TextTagParser tagParser = new TextTagParser();
List tokens = tagParser.Tokenize(tokenText);
- StartCoroutine(ProcessTokens(tokens, onComplete));
+ StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete));
}
virtual protected bool CheckParamCount(List paramList, int count)
@@ -368,7 +371,7 @@ namespace Fungus
return false;
}
- protected virtual IEnumerator ProcessTokens(List tokens, Action onComplete)
+ protected virtual IEnumerator ProcessTokens(List tokens, bool stopAudio, Action onComplete)
{
// Reset control members
boldActive = false;
@@ -583,7 +586,7 @@ namespace Fungus
isWaitingForInput = false;
isWriting = false;
- NotifyEnd();
+ NotifyEnd(stopAudio);
if (onComplete != null)
{
@@ -844,11 +847,11 @@ namespace Fungus
}
}
- protected virtual void NotifyEnd()
+ protected virtual void NotifyEnd(bool stopAudio)
{
foreach (IWriterListener writerListener in writerListeners)
{
- writerListener.OnEnd();
+ writerListener.OnEnd(stopAudio);
}
}
diff --git a/Assets/Fungus/UI/Scripts/WriterAudio.cs b/Assets/Fungus/UI/Scripts/WriterAudio.cs
index eb0f3b52..11f6e09e 100644
--- a/Assets/Fungus/UI/Scripts/WriterAudio.cs
+++ b/Assets/Fungus/UI/Scripts/WriterAudio.cs
@@ -209,9 +209,12 @@ namespace Fungus
Resume();
}
- public virtual void OnEnd()
+ public virtual void OnEnd(bool stopAudio)
{
- Stop();
+ if (stopAudio)
+ {
+ Stop();
+ }
}
public virtual void OnGlyph()