Browse Source

Merge pull request #402 from FungusGames/stop-say-audio

Stop say audio
master
Chris Gregan 9 years ago
parent
commit
4586c8ef04
  1. 3
      Assets/Fungus/Narrative/Editor/SayEditor.cs
  2. 5
      Assets/Fungus/Narrative/Scripts/Commands/Say.cs
  3. 8
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  4. 4
      Assets/Fungus/UI/Scripts/Commands/Write.cs
  5. 31
      Assets/Fungus/UI/Scripts/Writer.cs
  6. 7
      Assets/Fungus/UI/Scripts/WriterAudio.cs

3
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)

5
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();
});
}

8
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);
}

4
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 (); }
);
}

31
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
/// <param name="audioClip">An optional audioClip sound effect can be supplied (e.g. for voiceover)</param>
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.
/// <param name="stopAudio">Controls whether audio should be stopped when writing ends.</param>
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<TextTagParser.Token> tokens = tagParser.Tokenize(tokenText);
StartCoroutine(ProcessTokens(tokens, onComplete));
StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete));
}
virtual protected bool CheckParamCount(List<string> paramList, int count)
@ -368,7 +371,7 @@ namespace Fungus
return false;
}
protected virtual IEnumerator ProcessTokens(List<TextTagParser.Token> tokens, Action onComplete)
protected virtual IEnumerator ProcessTokens(List<TextTagParser.Token> 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);
}
}

7
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()

Loading…
Cancel
Save