diff --git a/Assets/Fungus/Audio/Scripts/Commands/PlayMusic.cs b/Assets/Fungus/Audio/Scripts/Commands/PlayMusic.cs index 7646997e..8a00509b 100644 --- a/Assets/Fungus/Audio/Scripts/Commands/PlayMusic.cs +++ b/Assets/Fungus/Audio/Scripts/Commands/PlayMusic.cs @@ -28,7 +28,7 @@ namespace Fungus public override void OnEnter() { - MusicController musicController = MusicController.GetInstance(); + IMusicController musicController = MusicController.GetInstance(); if (musicController != null) { float startTime = Mathf.Max(0, atTime); diff --git a/Assets/Fungus/Audio/Scripts/Commands/PlaySound.cs b/Assets/Fungus/Audio/Scripts/Commands/PlaySound.cs index f150e06b..ddc23318 100644 --- a/Assets/Fungus/Audio/Scripts/Commands/PlaySound.cs +++ b/Assets/Fungus/Audio/Scripts/Commands/PlaySound.cs @@ -32,7 +32,7 @@ namespace Fungus return; } - MusicController musicController = MusicController.GetInstance(); + IMusicController musicController = MusicController.GetInstance(); if (musicController != null) { musicController.PlaySound(soundClip, volume); diff --git a/Assets/Fungus/Audio/Scripts/Commands/SetAudioPitch.cs b/Assets/Fungus/Audio/Scripts/Commands/SetAudioPitch.cs index 3bec0305..6cff8015 100644 --- a/Assets/Fungus/Audio/Scripts/Commands/SetAudioPitch.cs +++ b/Assets/Fungus/Audio/Scripts/Commands/SetAudioPitch.cs @@ -34,7 +34,7 @@ namespace Fungus } }; - MusicController musicController = MusicController.GetInstance(); + IMusicController musicController = MusicController.GetInstance(); if (musicController != null) { musicController.SetAudioPitch(pitch, fadeDuration, onComplete); diff --git a/Assets/Fungus/Audio/Scripts/Commands/SetAudioVolume.cs b/Assets/Fungus/Audio/Scripts/Commands/SetAudioVolume.cs index 8297c1c0..c646488f 100644 --- a/Assets/Fungus/Audio/Scripts/Commands/SetAudioVolume.cs +++ b/Assets/Fungus/Audio/Scripts/Commands/SetAudioVolume.cs @@ -27,7 +27,7 @@ namespace Fungus public override void OnEnter() { - MusicController musicController = MusicController.GetInstance(); + IMusicController musicController = MusicController.GetInstance(); if (musicController != null) { musicController.SetAudioVolume(volume, fadeDuration, () => { diff --git a/Assets/Fungus/Audio/Scripts/Commands/StopMusic.cs b/Assets/Fungus/Audio/Scripts/Commands/StopMusic.cs index dd7728c8..7e5bbd88 100644 --- a/Assets/Fungus/Audio/Scripts/Commands/StopMusic.cs +++ b/Assets/Fungus/Audio/Scripts/Commands/StopMusic.cs @@ -16,7 +16,7 @@ namespace Fungus { public override void OnEnter() { - MusicController musicController = MusicController.GetInstance(); + IMusicController musicController = MusicController.GetInstance(); if (musicController != null) { musicController.StopMusic(); diff --git a/Assets/Fungus/Audio/Scripts/IMusicController.cs b/Assets/Fungus/Audio/Scripts/IMusicController.cs new file mode 100644 index 00000000..2ee37d7d --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/IMusicController.cs @@ -0,0 +1,45 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Music manager which provides basic music and sound effect functionality. + /// Music playback persists across scene loads. + /// + public interface IMusicController + { + /// + /// Plays game music using an audio clip. + /// One music clip may be played at a time. + /// + void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime); + + /// + /// Plays a sound effect once, at the specified volume. + /// + /// The sound effect clip to play. + /// The volume level of the sound effect. + void PlaySound(AudioClip soundClip, float volume); + + /// + /// Shifts the game music pitch to required value over a period of time. + /// + /// The new music pitch value. + /// The length of time in seconds needed to complete the pitch change. + /// A delegate method to call when the pitch shift has completed. + void SetAudioPitch(float pitch, float duration, System.Action onComplete); + + /// + /// Fades the game music volume to required level over a period of time. + /// + /// The new music volume value [0..1] + /// The length of time in seconds needed to complete the volume change. + /// Delegate function to call when fade completes. + void SetAudioVolume(float volume, float duration, System.Action onComplete); + + /// + /// Stops playing game music. + /// + void StopMusic(); + } +} diff --git a/Assets/Fungus/Audio/Scripts/IMusicController.cs.meta b/Assets/Fungus/Audio/Scripts/IMusicController.cs.meta new file mode 100644 index 00000000..520e1565 --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/IMusicController.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: efedec0242be143678aaa7075aa5467e +timeCreated: 1473429999 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Audio/Scripts/MusicController.cs b/Assets/Fungus/Audio/Scripts/MusicController.cs index 32777103..5a2dbed8 100644 --- a/Assets/Fungus/Audio/Scripts/MusicController.cs +++ b/Assets/Fungus/Audio/Scripts/MusicController.cs @@ -5,19 +5,16 @@ namespace Fungus { - /// - /// Singleton music manager component. - /// Provides basic music and sound effect functionality. - /// Music playback persists across scene loads. - /// [RequireComponent(typeof(AudioSource))] - public class MusicController : MonoBehaviour + public class MusicController : MonoBehaviour, IMusicController { - static MusicController instance; + static IMusicController instance; - // Returns the MusicController singleton instance. - // Will create a MusicController game object if none currently exists. - static public MusicController GetInstance() + /// + /// Returns the MusicController singleton instance. + /// Will create a MusicController game object if none currently exists. + /// + static public IMusicController GetInstance() { if (instance == null) { @@ -34,11 +31,9 @@ namespace Fungus GetComponent().playOnAwake = false; GetComponent().loop = true; } + + #region IMusicController implementation - /// - /// // Plays game music using an audio clip. - /// One music clip may be played at a time. - /// public void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime) { AudioSource audioSource = GetComponent(); @@ -72,36 +67,31 @@ namespace Fungus }); } } - - /// - /// Stops playing game music. - /// - public virtual void StopMusic() + + public virtual void PlaySound(AudioClip soundClip, float volume) { - GetComponent().Stop(); + GetComponent().PlayOneShot(soundClip, volume); } - /// - /// Fades the game music volume to required level over a period of time. - /// - /// The new music volume value [0..1] - /// The length of time in seconds needed to complete the volume change. - /// Delegate function to call when fade completes. - public virtual void SetAudioVolume(float volume, float duration, System.Action onComplete) + public virtual void SetAudioPitch(float pitch, float duration, System.Action onComplete) { AudioSource audio = GetComponent(); - if (Mathf.Approximately(duration, 0f)) + if (duration == 0f) { - audio.volume = volume; + audio.pitch = pitch; + if (onComplete != null) + { + onComplete(); + } return; } LeanTween.value(gameObject, - audio.volume, - volume, - duration).setOnUpdate( (v) => { - audio.volume = v; + audio.pitch, + pitch, + duration).setOnUpdate( (p) => { + audio.pitch = p; }).setOnComplete( () => { if (onComplete != null) { @@ -110,31 +100,21 @@ namespace Fungus }); } - /// - /// Shifts the game music pitch to required value over a period of time. - /// - /// The new music pitch value. - /// The length of time in seconds needed to complete the pitch change. - /// A delegate method to call when the pitch shift has completed. - public virtual void SetAudioPitch(float pitch, float duration, System.Action onComplete) + public virtual void SetAudioVolume(float volume, float duration, System.Action onComplete) { AudioSource audio = GetComponent(); - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { - audio.pitch = pitch; - if (onComplete != null) - { - onComplete(); - } + audio.volume = volume; return; } LeanTween.value(gameObject, - audio.pitch, - pitch, - duration).setOnUpdate( (p) => { - audio.pitch = p; + audio.volume, + volume, + duration).setOnUpdate( (v) => { + audio.volume = v; }).setOnComplete( () => { if (onComplete != null) { @@ -143,20 +123,11 @@ namespace Fungus }); } - /// - /// Plays a sound effect once, at the specified volume. - /// - /// The sound effect clip to play. - /// The volume level of the sound effect. - public virtual void PlaySound(AudioClip soundClip, float volume) + public virtual void StopMusic() { - GetComponent().PlayOneShot(soundClip, volume); + GetComponent().Stop(); } - public virtual void PlaySoundAtTime(AudioClip soundClip, float volume, float atTime) - { - GetComponent().time = atTime; // This may not work BK - GetComponent().PlayOneShot(soundClip, volume); - } + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Narrative/Scripts/IMenuDialog.cs b/Assets/Fungus/Narrative/Scripts/IMenuDialog.cs index f3cadeff..383a298b 100644 --- a/Assets/Fungus/Narrative/Scripts/IMenuDialog.cs +++ b/Assets/Fungus/Narrative/Scripts/IMenuDialog.cs @@ -1,5 +1,4 @@ using UnityEngine; -using System.Collections; namespace Fungus { diff --git a/Assets/Fungus/Narrative/Scripts/ISayDialog.cs b/Assets/Fungus/Narrative/Scripts/ISayDialog.cs index 71c65b8d..dd93b925 100644 --- a/Assets/Fungus/Narrative/Scripts/ISayDialog.cs +++ b/Assets/Fungus/Narrative/Scripts/ISayDialog.cs @@ -1,5 +1,4 @@ using UnityEngine; -using System.Collections; namespace Fungus {