internal static IEnumerator PlaySound(Enums.AudioSounds audioType, Action onMusicStopPlay) { if (Level.GetInstance.GameFinished) { yield break; } GameObject _gameObj = audioSoundsGameObjects.Dequeue(); AudioSource audioSource = _gameObj.GetComponent <AudioSource>(); if (AudioAssets.GetInstance().GetSound(audioType) != null) { if (audioType == Enums.AudioSounds.BackGroundMusic) { backMusic = audioSource; } audioSource.clip = AudioAssets.GetInstance().GetSound(audioType); _gameObj.SetActive(true); audioSource.Play(); } currentPlaingAudioSounds.Add(audioSource); yield return(new WaitWhile(() => audioSource.isPlaying)); currentPlaingAudioSounds.Remove(audioSource); audioSoundsGameObjects.Enqueue(audioSource.gameObject); audioSource.gameObject.SetActive(false); onMusicStopPlay?.Invoke(); }
internal void SetSound(Enums.AudioSounds audioType, AudioClip audioClip) { audioSources.SetAudioByKey(audioType, audioClip); }
internal AudioClip GetSound(Enums.AudioSounds audioType) { return(audioSources.FindAudioByKey(audioType)); }