override public float Run() { if (runtimeSound == null) { return(0f); } if (!isRunning) { isRunning = true; if (ignoreIfPlaying && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)) { if ((audioClip != null && runtimeSound.IsPlaying(audioClip)) || (audioClip == null && runtimeSound.IsPlaying())) { // Sound object is already playing the desired clip return(0f); } } if (audioClip && runtimeSound.GetComponent <AudioSource>()) { if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn) { runtimeSound.GetComponent <AudioSource>().clip = audioClip; } } if (runtimeSound.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)) { Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[]; foreach (Sound sound in sounds) { sound.EndOld(SoundType.Music, runtimeSound); } } if (soundAction == SoundAction.Play) { runtimeSound.Play(loop); if (!loop && willWait) { return(defaultPauseTime); } } else if (soundAction == SoundAction.FadeIn) { if (fadeTime <= 0f) { runtimeSound.Play(loop); } else { runtimeSound.FadeIn(fadeTime, loop); if (!loop && willWait) { return(defaultPauseTime); } } } else if (soundAction == SoundAction.FadeOut) { if (fadeTime <= 0f) { runtimeSound.Stop(); } else { runtimeSound.FadeOut(fadeTime); if (willWait) { return(fadeTime); } } } else if (soundAction == SoundAction.Stop) { runtimeSound.Stop(); if (affectChildren) { foreach (Transform child in runtimeSound.transform) { if (child.GetComponent <Sound>()) { child.GetComponent <Sound>().Stop(); } } } } } else { if (soundAction == SoundAction.FadeOut) { isRunning = false; return(0f); } if (runtimeSound.IsPlaying()) { return(defaultPauseTime); } else { isRunning = false; } } return(0f); }
override public float Run() { if (soundObject) { if ((audioClip != null && soundObject.IsPlaying(audioClip)) || (audioClip == null && soundObject.IsPlaying())) { // Sound object is already playing the desired clip if (ignoreIfPlaying && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)) { return(0f); } } if (audioClip && soundObject.GetComponent <AudioSource>()) { if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn) { soundObject.GetComponent <AudioSource>().clip = audioClip; } } if (soundObject.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)) { Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[]; foreach (Sound sound in sounds) { sound.EndOldMusic(soundObject); } } if (soundAction == SoundAction.Play) { soundObject.Play(loop); } else if (soundAction == SoundAction.FadeIn) { if (fadeTime == 0f) { soundObject.Play(loop); } else { soundObject.FadeIn(fadeTime, loop); } } else if (soundAction == SoundAction.FadeOut) { if (fadeTime == 0f) { soundObject.Stop(); } else { soundObject.FadeOut(fadeTime); } } else if (soundAction == SoundAction.Stop) { soundObject.Stop(); if (affectChildren) { foreach (Transform child in soundObject.transform) { if (child.GetComponent <Sound>()) { child.GetComponent <Sound>().Stop(); } } } } } return(0f); }