Browse Source

Refactored WriterAudio to only expose public IWriterAudio methods

master
Christopher 8 years ago
parent
commit
33985dedbd
  1. 2
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  2. 7
      Assets/Fungus/UI/Scripts/IWriter.cs
  3. 48
      Assets/Fungus/UI/Scripts/WriterAudio.cs

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

@ -181,7 +181,7 @@ namespace Fungus
if (voiceOverClip != null) if (voiceOverClip != null)
{ {
WriterAudio writerAudio = GetWriterAudio(); WriterAudio writerAudio = GetWriterAudio();
writerAudio.PlayVoiceover(voiceOverClip); writerAudio.OnVoiceover(voiceOverClip);
} }
else if (speakingCharacter != null) else if (speakingCharacter != null)
{ {

7
Assets/Fungus/UI/Scripts/IWriter.cs

@ -65,11 +65,16 @@ namespace Fungus
/// Called when the Writer has resumed writing text. /// Called when the Writer has resumed writing text.
void OnResume(); void OnResume();
/// Called when the Writer has finshed writing text. /// Called when the Writer has finished writing text.
/// <param name="stopAudio">Controls whether audio should be stopped when writing ends.</param> /// <param name="stopAudio">Controls whether audio should be stopped when writing ends.</param>
void OnEnd(bool stopAudio); 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(); void OnGlyph();
/// <summary>
/// Called when voiceover should start.
/// </summary>
void OnVoiceover(AudioClip voiceOverClip);
} }
} }

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

@ -51,7 +51,7 @@ namespace Fungus
// Time when current beep will have finished playing // Time when current beep will have finished playing
protected float nextBeepTime; protected float nextBeepTime;
public virtual void SetAudioMode(AudioMode mode) protected virtual void SetAudioMode(AudioMode mode)
{ {
audioMode = mode; audioMode = mode;
} }
@ -71,29 +71,7 @@ namespace Fungus
targetAudioSource.volume = 0f; targetAudioSource.volume = 0f;
} }
/// <summary> protected virtual void Play(AudioClip audioClip)
/// 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.
/// </summary>
public virtual void PlayVoiceover(AudioClip voiceOverClip)
{
if (targetAudioSource == null)
{
return;
}
playingVoiceover = true;
targetAudioSource.volume = volume;
targetVolume = volume;
targetAudioSource.loop = false;
targetAudioSource.clip = voiceOverClip;
targetAudioSource.Play();
}
public virtual void Play(AudioClip audioClip)
{ {
if (targetAudioSource == null || if (targetAudioSource == null ||
(audioMode == AudioMode.SoundEffect && soundEffect == null && audioClip == null) || (audioMode == AudioMode.SoundEffect && soundEffect == null && audioClip == null) ||
@ -130,7 +108,7 @@ namespace Fungus
} }
} }
public virtual void Pause() protected virtual void Pause()
{ {
if (targetAudioSource == null) if (targetAudioSource == null)
{ {
@ -141,7 +119,7 @@ namespace Fungus
targetVolume = 0f; targetVolume = 0f;
} }
public virtual void Stop() protected virtual void Stop()
{ {
if (targetAudioSource == null) if (targetAudioSource == null)
{ {
@ -156,7 +134,7 @@ namespace Fungus
playingVoiceover = false; playingVoiceover = false;
} }
public virtual void Resume() protected virtual void Resume()
{ {
if (targetAudioSource == null) if (targetAudioSource == null)
{ {
@ -246,6 +224,22 @@ namespace Fungus
} }
} }
public virtual void OnVoiceover(AudioClip voiceOverClip)
{
if (targetAudioSource == null)
{
return;
}
playingVoiceover = true;
targetAudioSource.volume = volume;
targetVolume = volume;
targetAudioSource.loop = false;
targetAudioSource.clip = voiceOverClip;
targetAudioSource.Play();
}
#endregion #endregion
} }
} }
Loading…
Cancel
Save