Browse Source

Reverted IMusicController interface

master
Christopher 8 years ago
parent
commit
2ec4c818f2
  1. 2
      Assets/Fungus/Scripts/Commands/PlayMusic.cs
  2. 2
      Assets/Fungus/Scripts/Commands/PlaySound.cs
  3. 2
      Assets/Fungus/Scripts/Commands/SetAudioPitch.cs
  4. 2
      Assets/Fungus/Scripts/Commands/SetAudioVolume.cs
  5. 2
      Assets/Fungus/Scripts/Commands/StopMusic.cs
  6. 36
      Assets/Fungus/Scripts/Components/MusicController.cs
  7. 48
      Assets/Fungus/Scripts/Interfaces/IMusicController.cs
  8. 12
      Assets/Fungus/Scripts/Interfaces/IMusicController.cs.meta

2
Assets/Fungus/Scripts/Commands/PlayMusic.cs

@ -28,7 +28,7 @@ namespace Fungus.Commands
public override void OnEnter() public override void OnEnter()
{ {
IMusicController musicController = MusicController.GetInstance(); var musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
float startTime = Mathf.Max(0, atTime); float startTime = Mathf.Max(0, atTime);

2
Assets/Fungus/Scripts/Commands/PlaySound.cs

@ -32,7 +32,7 @@ namespace Fungus.Commands
return; return;
} }
IMusicController musicController = MusicController.GetInstance(); var musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
musicController.PlaySound(soundClip, volume); musicController.PlaySound(soundClip, volume);

2
Assets/Fungus/Scripts/Commands/SetAudioPitch.cs

@ -34,7 +34,7 @@ namespace Fungus.Commands
} }
}; };
IMusicController musicController = MusicController.GetInstance(); var musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
musicController.SetAudioPitch(pitch, fadeDuration, onComplete); musicController.SetAudioPitch(pitch, fadeDuration, onComplete);

2
Assets/Fungus/Scripts/Commands/SetAudioVolume.cs

@ -27,7 +27,7 @@ namespace Fungus.Commands
public override void OnEnter() public override void OnEnter()
{ {
IMusicController musicController = MusicController.GetInstance(); var musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
musicController.SetAudioVolume(volume, fadeDuration, () => { musicController.SetAudioVolume(volume, fadeDuration, () => {

2
Assets/Fungus/Scripts/Commands/StopMusic.cs

@ -16,7 +16,7 @@ namespace Fungus.Commands
{ {
public override void OnEnter() public override void OnEnter()
{ {
IMusicController musicController = MusicController.GetInstance(); var musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
musicController.StopMusic(); musicController.StopMusic();

36
Assets/Fungus/Scripts/Components/MusicController.cs

@ -5,16 +5,20 @@
namespace Fungus namespace Fungus
{ {
/// <summary>
/// Music manager which provides basic music and sound effect functionality.
/// Music playback persists across scene loads.
/// </summary>
[RequireComponent(typeof(AudioSource))] [RequireComponent(typeof(AudioSource))]
public class MusicController : MonoBehaviour, IMusicController public class MusicController : MonoBehaviour
{ {
static IMusicController instance; static MusicController instance;
/// <summary> /// <summary>
/// Returns the MusicController singleton instance. /// Returns the MusicController singleton instance.
/// Will create a MusicController game object if none currently exists. /// Will create a MusicController game object if none currently exists.
/// </summary> /// </summary>
static public IMusicController GetInstance() static public MusicController GetInstance()
{ {
if (instance == null) if (instance == null)
{ {
@ -32,8 +36,12 @@ namespace Fungus
GetComponent<AudioSource>().loop = true; GetComponent<AudioSource>().loop = true;
} }
#region IMusicController implementation #region Public methods
/// <summary>
/// Plays game music using an audio clip.
/// One music clip may be played at a time.
/// </summary>
public void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime) public void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime)
{ {
AudioSource audioSource = GetComponent<AudioSource>(); AudioSource audioSource = GetComponent<AudioSource>();
@ -68,11 +76,22 @@ namespace Fungus
} }
} }
/// <summary>
/// Plays a sound effect once, at the specified volume.
/// </summary>
/// <param name="soundClip">The sound effect clip to play.</param>
/// <param name="volume">The volume level of the sound effect.</param>
public virtual void PlaySound(AudioClip soundClip, float volume) public virtual void PlaySound(AudioClip soundClip, float volume)
{ {
GetComponent<AudioSource>().PlayOneShot(soundClip, volume); GetComponent<AudioSource>().PlayOneShot(soundClip, volume);
} }
/// <summary>
/// Shifts the game music pitch to required value over a period of time.
/// </summary>
/// <param name="pitch">The new music pitch value.</param>
/// <param name="duration">The length of time in seconds needed to complete the pitch change.</param>
/// <param name="onComplete">A delegate method to call when the pitch shift has completed.</param>
public virtual void SetAudioPitch(float pitch, float duration, System.Action onComplete) public virtual void SetAudioPitch(float pitch, float duration, System.Action onComplete)
{ {
AudioSource audio = GetComponent<AudioSource>(); AudioSource audio = GetComponent<AudioSource>();
@ -100,6 +119,12 @@ namespace Fungus
}); });
} }
/// <summary>
/// Fades the game music volume to required level over a period of time.
/// </summary>
/// <param name="volume">The new music volume value [0..1]</param>
/// <param name="duration">The length of time in seconds needed to complete the volume change.</param>
/// <param name="onComplete">Delegate function to call when fade completes.</param>
public virtual void SetAudioVolume(float volume, float duration, System.Action onComplete) public virtual void SetAudioVolume(float volume, float duration, System.Action onComplete)
{ {
AudioSource audio = GetComponent<AudioSource>(); AudioSource audio = GetComponent<AudioSource>();
@ -123,6 +148,9 @@ namespace Fungus
}); });
} }
/// <summary>
/// Stops playing game music.
/// </summary>
public virtual void StopMusic() public virtual void StopMusic()
{ {
GetComponent<AudioSource>().Stop(); GetComponent<AudioSource>().Stop();

48
Assets/Fungus/Scripts/Interfaces/IMusicController.cs

@ -1,48 +0,0 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
namespace Fungus
{
/// <summary>
/// Music manager which provides basic music and sound effect functionality.
/// Music playback persists across scene loads.
/// </summary>
public interface IMusicController
{
/// <summary>
/// Plays game music using an audio clip.
/// One music clip may be played at a time.
/// </summary>
void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime);
/// <summary>
/// Plays a sound effect once, at the specified volume.
/// </summary>
/// <param name="soundClip">The sound effect clip to play.</param>
/// <param name="volume">The volume level of the sound effect.</param>
void PlaySound(AudioClip soundClip, float volume);
/// <summary>
/// Shifts the game music pitch to required value over a period of time.
/// </summary>
/// <param name="pitch">The new music pitch value.</param>
/// <param name="duration">The length of time in seconds needed to complete the pitch change.</param>
/// <param name="onComplete">A delegate method to call when the pitch shift has completed.</param>
void SetAudioPitch(float pitch, float duration, System.Action onComplete);
/// <summary>
/// Fades the game music volume to required level over a period of time.
/// </summary>
/// <param name="volume">The new music volume value [0..1]</param>
/// <param name="duration">The length of time in seconds needed to complete the volume change.</param>
/// <param name="onComplete">Delegate function to call when fade completes.</param>
void SetAudioVolume(float volume, float duration, System.Action onComplete);
/// <summary>
/// Stops playing game music.
/// </summary>
void StopMusic();
}
}

12
Assets/Fungus/Scripts/Interfaces/IMusicController.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: efedec0242be143678aaa7075aa5467e
timeCreated: 1473429999
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save