Browse Source

Merge pull request #285 from FungusGames/fix-voice-over-clips

Fixed voiceover clips not playing correctly in Say command #273
master
Chris Gregan 9 years ago
parent
commit
59b5b28882
  1. 23
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  2. 44
      Assets/Fungus/UI/Scripts/WriterAudio.cs
  3. 1463
      Assets/Tests/Narrative/NarrativeTests.unity
  4. BIN
      Assets/Tests/TestAssets/Audio/VoiceOver.wav
  5. 22
      Assets/Tests/TestAssets/Audio/VoiceOver.wav.meta

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

@ -129,12 +129,12 @@ namespace Fungus
}
}
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip audioClip, Action onComplete)
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip voiceOverClip, Action onComplete)
{
StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, audioClip, onComplete));
StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, voiceOverClip, onComplete));
}
protected virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip audioClip, Action onComplete)
protected virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, AudioClip voiceOverClip, Action onComplete)
{
Writer writer = GetWriter();
@ -148,15 +148,20 @@ namespace Fungus
this.fadeWhenDone = fadeWhenDone;
// Look for a character sound effect if no voice over clip is specified
AudioClip clip = audioClip;
if (speakingCharacter != null &&
clip == null)
// Voice over clip takes precedence over a character sound effect if provided
AudioClip soundEffectClip = null;
if (voiceOverClip != null)
{
WriterAudio writerAudio = GetWriterAudio();
writerAudio.PlayVoiceover(voiceOverClip);
}
else if (speakingCharacter != null)
{
clip = speakingCharacter.soundEffect;
soundEffectClip = speakingCharacter.soundEffect;
}
writer.Write(text, clearPrevious, waitForInput, soundEffectClip, onComplete);
writer.Write(text, clearPrevious, waitForInput, clip, onComplete);
}
protected virtual void LateUpdate()

44
Assets/Fungus/UI/Scripts/WriterAudio.cs

@ -43,6 +43,9 @@ namespace Fungus
// When true, a beep will be played on every written character glyph
protected bool playBeeps;
// True when a voiceover clip is playing
protected bool playingVoiceover = false;
public virtual void SetAudioMode(AudioMode mode)
{
audioMode = mode;
@ -63,6 +66,28 @@ namespace Fungus
targetAudioSource.volume = 0f;
}
/**
* Plays a voiceover audio clip.
* Voiceover behaves differently than speaking sound effects because it
* should keep on playing after the text has finished writing. It also
* does not pause for wait tags, punctuation, etc.
*/
public virtual void PlayVoiceover(AudioClip voiceOverClip)
{
if (targetAudioSource == null)
{
return;
}
playingVoiceover = true;
targetAudioSource.volume = 1f;
targetVolume = 1f;
targetAudioSource.loop = false;
targetAudioSource.clip = voiceOverClip;
targetAudioSource.Play();
}
public virtual void Play(AudioClip audioClip)
{
if (targetAudioSource == null ||
@ -72,6 +97,7 @@ namespace Fungus
return;
}
playingVoiceover = false;
targetAudioSource.volume = 0f;
targetVolume = 1f;
@ -122,6 +148,7 @@ namespace Fungus
targetVolume = 0f;
targetAudioSource.loop = false;
playBeeps = false;
playingVoiceover = false;
}
public virtual void Resume()
@ -154,16 +181,28 @@ namespace Fungus
public virtual void OnStart(AudioClip audioClip)
{
if (playingVoiceover)
{
return;
}
Play(audioClip);
}
public virtual void OnPause()
{
if (playingVoiceover)
{
return;
}
Pause();
}
public virtual void OnResume()
{
if (playingVoiceover)
{
return;
}
Resume();
}
@ -174,6 +213,11 @@ namespace Fungus
public virtual void OnGlyph()
{
if (playingVoiceover)
{
return;
}
if (playBeeps && beepSounds.Count > 0)
{
if (!targetAudioSource.isPlaying)

1463
Assets/Tests/Narrative/NarrativeTests.unity

File diff suppressed because it is too large Load Diff

BIN
Assets/Tests/TestAssets/Audio/VoiceOver.wav

Binary file not shown.

22
Assets/Tests/TestAssets/Audio/VoiceOver.wav.meta

@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 9301ee931368e4d8997d0c272b06fe91
timeCreated: 1444296783
licenseType: Free
AudioImporter:
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save