diff --git a/Assets/Fungus/Scripts/Commands/PlayAmbienceSound.cs b/Assets/Fungus/Scripts/Commands/PlayAmbianceSound.cs
similarity index 100%
rename from Assets/Fungus/Scripts/Commands/PlayAmbienceSound.cs
rename to Assets/Fungus/Scripts/Commands/PlayAmbianceSound.cs
diff --git a/Assets/Fungus/Scripts/Commands/PlayAmbienceSound.cs.meta b/Assets/Fungus/Scripts/Commands/PlayAmbienceSound.cs.meta
deleted file mode 100644
index 17d2cdd6..00000000
--- a/Assets/Fungus/Scripts/Commands/PlayAmbienceSound.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 1e466cf468c490144a240a8f7a566455
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Commands/StopAmbiance.cs b/Assets/Fungus/Scripts/Commands/StopAmbiance.cs
new file mode 100644
index 00000000..b3130c06
--- /dev/null
+++ b/Assets/Fungus/Scripts/Commands/StopAmbiance.cs
@@ -0,0 +1,35 @@
+// 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
+{
+ ///
+ /// Stops the currently playing game music.
+ ///
+ [CommandInfo("Audio",
+ "Stop Ambiance",
+ "Stops the currently playing game ambiance.")]
+ [AddComponentMenu("")]
+ public class StopAmbiance : Command
+ {
+ #region Public members
+
+ public override void OnEnter()
+ {
+ var musicManager = FungusManager.Instance.MusicManager;
+
+ musicManager.StopAmbiance();
+
+ Continue();
+ }
+
+ public override Color GetButtonColor()
+ {
+ return new Color32(242, 209, 176, 255);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Scripts/Components/MusicManager.cs b/Assets/Fungus/Scripts/Components/MusicManager.cs
index 1dcaa7f0..8ea094d9 100644
--- a/Assets/Fungus/Scripts/Components/MusicManager.cs
+++ b/Assets/Fungus/Scripts/Components/MusicManager.cs
@@ -1,7 +1,7 @@
// 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;
+using UnityEngine;
namespace Fungus
{
@@ -9,14 +9,25 @@ namespace Fungus
/// Music manager which provides basic music and sound effect functionality.
/// Music playback persists across scene loads.
///
- [RequireComponent(typeof(AudioSource))]
+ //[RequireComponent(typeof(AudioSource))]
public class MusicManager : MonoBehaviour
{
protected AudioSource audioSource;
+ protected AudioSource audioSourceAmbiance;
+
+ void Reset()
+ {
+ int audioSourceCount = this.GetComponents().Length;
+ for (int i = 0; i < 2 - audioSourceCount; i++)
+ gameObject.AddComponent();
+
+ }
protected virtual void Awake()
{
- audioSource = GetComponent();
+ Reset();
+ audioSource = GetComponents()[0];
+ audioSourceAmbiance = GetComponents()[1];
}
protected virtual void Start()
@@ -50,10 +61,10 @@ namespace Fungus
float startVolume = audioSource.volume;
LeanTween.value(gameObject, startVolume, 0f, fadeDuration)
- .setOnUpdate( (v) => {
+ .setOnUpdate((v) => {
// Fade out current music
audioSource.volume = v;
- }).setOnComplete( () => {
+ }).setOnComplete(() => {
// Play new music
audioSource.volume = startVolume;
audioSource.clip = musicClip;
@@ -82,10 +93,10 @@ namespace Fungus
/// The volume level of the sound effect.
public virtual void PlayAmbianceSound(AudioClip soundClip, bool loop, float volume)
{
- audioSource.loop = loop;
- audioSource.clip = soundClip;
- audioSource.volume = volume;
- audioSource.Play();
+ audioSourceAmbiance.loop = loop;
+ audioSourceAmbiance.clip = soundClip;
+ audioSourceAmbiance.volume = volume;
+ audioSourceAmbiance.Play();
}
///
@@ -99,6 +110,7 @@ namespace Fungus
if (Mathf.Approximately(duration, 0f))
{
audioSource.pitch = pitch;
+ audioSourceAmbiance.pitch = pitch;
if (onComplete != null)
{
onComplete();
@@ -106,12 +118,15 @@ namespace Fungus
return;
}
- LeanTween.value(gameObject,
- audioSource.pitch,
- pitch,
- duration).setOnUpdate( (p) => {
+ LeanTween.value(gameObject,
+ audioSource.pitch,
+ pitch,
+ duration).setOnUpdate((p) =>
+ {
audioSource.pitch = p;
- }).setOnComplete( () => {
+ audioSourceAmbiance.pitch = p;
+ }).setOnComplete(() =>
+ {
if (onComplete != null)
{
onComplete();
@@ -129,20 +144,22 @@ namespace Fungus
{
if (Mathf.Approximately(duration, 0f))
{
- if (onComplete != null)
- {
- onComplete();
- }
+ if (onComplete != null)
+ {
+ onComplete();
+ }
audioSource.volume = volume;
+ audioSourceAmbiance.volume = volume;
return;
}
- LeanTween.value(gameObject,
- audioSource.volume,
- volume,
- duration).setOnUpdate( (v) => {
+ LeanTween.value(gameObject,
+ audioSource.volume,
+ volume,
+ duration).setOnUpdate((v) => {
audioSource.volume = v;
- }).setOnComplete( () => {
+ audioSourceAmbiance.volume = v;
+ }).setOnComplete(() => {
if (onComplete != null)
{
onComplete();
@@ -159,6 +176,15 @@ namespace Fungus
audioSource.clip = null;
}
+ ///
+ /// Stops playing game ambiance.
+ ///
+ public virtual void StopAmbiance()
+ {
+ audioSourceAmbiance.Stop();
+ audioSourceAmbiance.clip = null;
+ }
+
#endregion
}
}
\ No newline at end of file