public void PlayBackgroundMusic(AudioClip clip, AudioOptions audioOptions) { var audioSource = _backgroundMusicPooler.GetNextObject(); audioSource.AudioSource.clip = clip; if (audioOptions.WithFade) { StartCoroutine(AudioFades.FadeIn(audioSource.AudioSource, audioOptions.FadeSpeed, audioOptions.Volume)); } else { audioSource.AudioSource.volume = audioOptions.Volume; audioSource.AudioSource.Play(); } }
public void StopAllBackgroundMusic(AudioOptions audioOptions) { foreach (var audioSourcePooleable in _backgroundMusicPooler.ActiveObjects) { if (audioOptions.WithFade) { StartCoroutine(AudioFades.FadeOut(audioSourcePooleable, audioOptions.FadeSpeed)); } else { audioSourcePooleable.AudioSource.Stop(); audioSourcePooleable.Deactivate(); } } }
public void PlaySound(AudioClip clip, AudioOptions audioOptions) { audioOptions.LowPassFilter = _paused; var audioSource = audioOptions.LowPassFilter ? _lowPassFilterPooler.GetNextObject() : _audioClipPooler.GetNextObject(); audioSource.SetClip(clip); audioSource.StartClip(); if (audioOptions.WithFade) { StartCoroutine(AudioFades.FadeIn(audioSource.AudioSource, audioOptions.FadeSpeed, audioOptions.Volume)); } else { audioSource.SetVolume(audioOptions.Volume); } }