Browse Source

Reverted change removing StopAudioWithSameTag() #84

master
chrisgregan 10 years ago
parent
commit
77960063ee
  1. 35
      Assets/Fungus/Audio/Scripts/Commands/ControlAudio.cs

35
Assets/Fungus/Audio/Scripts/Commands/ControlAudio.cs

@ -47,18 +47,18 @@ namespace Fungus
switch(control) switch(control)
{ {
case controlType.PlayOnce: case controlType.PlayOnce:
StopAudio(); StopAudioWithSameTag();
PlayOnce(); PlayOnce();
break; break;
case controlType.PlayLoop: case controlType.PlayLoop:
StopAudio(); StopAudioWithSameTag();
PlayLoop(); PlayLoop();
break; break;
case controlType.PauseLoop: case controlType.PauseLoop:
PauseLoop(); PauseLoop();
break; break;
case controlType.StopLoop: case controlType.StopLoop:
StopLoop(); StopLoop(audioSource);
break; break;
case controlType.ChangeVolume: case controlType.ChangeVolume:
ChangeVolume(); ChangeVolume();
@ -70,14 +70,21 @@ namespace Fungus
} }
} }
protected void StopAudio() /**
* If there's other music playing in the scene, assign it the same tag as the new music you want to play and
* the old music will be automatically stopped.
*/
protected void StopAudioWithSameTag()
{ {
if (audioSource == null) AudioSource[] audioSources = GameObject.FindObjectsOfType<AudioSource>();
foreach (AudioSource a in audioSources)
{ {
return; if ((a.audio != audioSource) && (a.tag == audioSource.tag))
{
StopLoop(a.audio);
}
} }
StopLoop();
} }
protected void PlayOnce() protected void PlayOnce()
@ -159,23 +166,22 @@ namespace Fungus
else else
{ {
audioSource.audio.Pause(); audioSource.audio.Pause();
Continue();
} }
} }
protected void StopLoop() protected void StopLoop(AudioSource source)
{ {
if (fadeDuration > 0) if (fadeDuration > 0)
{ {
LeanTween.value(audioSource.gameObject,audioSource.volume,0,fadeDuration LeanTween.value(source.gameObject,audioSource.volume,0,fadeDuration
).setOnUpdate( ).setOnUpdate(
(float updateVolume)=>{ (float updateVolume)=>{
audioSource.volume = updateVolume; source.volume = updateVolume;
} }
).setOnComplete( ).setOnComplete(
()=>{ ()=>{
audioSource.audio.Stop(); source.audio.Stop();
if (waitUntilFinished) if (waitUntilFinished)
{ {
Continue(); Continue();
@ -185,7 +191,7 @@ namespace Fungus
} }
else else
{ {
audioSource.audio.Stop(); source.audio.Stop();
} }
} }
@ -199,7 +205,6 @@ namespace Fungus
); );
} }
// Allows ControlAudio to "Wait Until Finished" playing audio before moving onto the next command // Allows ControlAudio to "Wait Until Finished" playing audio before moving onto the next command
public delegate void AudioCallback(); public delegate void AudioCallback();

Loading…
Cancel
Save