|
|
|
@ -54,49 +54,10 @@ namespace Fungus.Commands
|
|
|
|
|
|
|
|
|
|
[Tooltip("Wait until this command has finished before executing the next command.")] |
|
|
|
|
[SerializeField] protected bool waitUntilFinished = false; |
|
|
|
|
|
|
|
|
|
public override void OnEnter() |
|
|
|
|
{ |
|
|
|
|
if (_audioSource.Value == null) |
|
|
|
|
{ |
|
|
|
|
Continue(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (control != ControlAudioType.ChangeVolume) |
|
|
|
|
{ |
|
|
|
|
_audioSource.Value.volume = endVolume; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch(control) |
|
|
|
|
{ |
|
|
|
|
case ControlAudioType.PlayOnce: |
|
|
|
|
StopAudioWithSameTag(); |
|
|
|
|
PlayOnce(); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.PlayLoop: |
|
|
|
|
StopAudioWithSameTag(); |
|
|
|
|
PlayLoop(); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.PauseLoop: |
|
|
|
|
PauseLoop(); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.StopLoop: |
|
|
|
|
StopLoop(_audioSource.Value); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.ChangeVolume: |
|
|
|
|
ChangeVolume(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (!waitUntilFinished) |
|
|
|
|
{ |
|
|
|
|
Continue(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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() |
|
|
|
|
protected virtual void StopAudioWithSameTag() |
|
|
|
|
{ |
|
|
|
|
// Don't stop audio if there's no tag assigned |
|
|
|
|
if (_audioSource.Value == null || |
|
|
|
@ -115,15 +76,15 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void PlayOnce() |
|
|
|
|
protected virtual void PlayOnce() |
|
|
|
|
{ |
|
|
|
|
if (fadeDuration > 0) |
|
|
|
|
{ |
|
|
|
|
// Fade volume in |
|
|
|
|
LeanTween.value(_audioSource.Value.gameObject, |
|
|
|
|
_audioSource.Value.volume, |
|
|
|
|
endVolume, |
|
|
|
|
fadeDuration |
|
|
|
|
_audioSource.Value.volume, |
|
|
|
|
endVolume, |
|
|
|
|
fadeDuration |
|
|
|
|
).setOnUpdate( |
|
|
|
|
(float updateVolume)=>{ |
|
|
|
|
_audioSource.Value.volume = updateVolume; |
|
|
|
@ -150,7 +111,7 @@ namespace Fungus.Commands
|
|
|
|
|
Continue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void PlayLoop() |
|
|
|
|
protected virtual void PlayLoop() |
|
|
|
|
{ |
|
|
|
|
if (fadeDuration > 0) |
|
|
|
|
{ |
|
|
|
@ -179,7 +140,7 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void PauseLoop() |
|
|
|
|
protected virtual void PauseLoop() |
|
|
|
|
{ |
|
|
|
|
if (fadeDuration > 0) |
|
|
|
|
{ |
|
|
|
@ -190,7 +151,7 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
).setOnComplete( |
|
|
|
|
()=>{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_audioSource.Value.GetComponent<AudioSource>().Pause(); |
|
|
|
|
if (waitUntilFinished) |
|
|
|
|
{ |
|
|
|
@ -205,7 +166,7 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void StopLoop(AudioSource source) |
|
|
|
|
protected virtual void StopLoop(AudioSource source) |
|
|
|
|
{ |
|
|
|
|
if (fadeDuration > 0) |
|
|
|
|
{ |
|
|
|
@ -216,7 +177,7 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
).setOnComplete( |
|
|
|
|
()=>{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source.GetComponent<AudioSource>().Stop(); |
|
|
|
|
if (waitUntilFinished) |
|
|
|
|
{ |
|
|
|
@ -231,7 +192,7 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void ChangeVolume() |
|
|
|
|
protected virtual void ChangeVolume() |
|
|
|
|
{ |
|
|
|
|
LeanTween.value(_audioSource.Value.gameObject,_audioSource.Value.volume,endVolume,fadeDuration |
|
|
|
|
).setOnUpdate( |
|
|
|
@ -246,7 +207,7 @@ namespace Fungus.Commands
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AudioFinished() |
|
|
|
|
protected virtual void AudioFinished() |
|
|
|
|
{ |
|
|
|
|
if (waitUntilFinished) |
|
|
|
|
{ |
|
|
|
@ -254,6 +215,47 @@ namespace Fungus.Commands
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Public members |
|
|
|
|
|
|
|
|
|
public override void OnEnter() |
|
|
|
|
{ |
|
|
|
|
if (_audioSource.Value == null) |
|
|
|
|
{ |
|
|
|
|
Continue(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (control != ControlAudioType.ChangeVolume) |
|
|
|
|
{ |
|
|
|
|
_audioSource.Value.volume = endVolume; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch(control) |
|
|
|
|
{ |
|
|
|
|
case ControlAudioType.PlayOnce: |
|
|
|
|
StopAudioWithSameTag(); |
|
|
|
|
PlayOnce(); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.PlayLoop: |
|
|
|
|
StopAudioWithSameTag(); |
|
|
|
|
PlayLoop(); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.PauseLoop: |
|
|
|
|
PauseLoop(); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.StopLoop: |
|
|
|
|
StopLoop(_audioSource.Value); |
|
|
|
|
break; |
|
|
|
|
case ControlAudioType.ChangeVolume: |
|
|
|
|
ChangeVolume(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (!waitUntilFinished) |
|
|
|
|
{ |
|
|
|
|
Continue(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string GetSummary() |
|
|
|
|
{ |
|
|
|
|
if (_audioSource.Value == null) |
|
|
|
@ -282,6 +284,8 @@ namespace Fungus.Commands
|
|
|
|
|
return new Color32(242, 209, 176, 255); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Backwards compatibility |
|
|
|
|
|
|
|
|
|
[HideInInspector] [FormerlySerializedAs("audioSource")] public AudioSource audioSourceOLD; |
|
|
|
|