예제 #1
0
    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();
    }
예제 #2
0
 internal void SetSound(Enums.AudioSounds audioType, AudioClip audioClip)
 {
     audioSources.SetAudioByKey(audioType, audioClip);
 }
예제 #3
0
 internal AudioClip GetSound(Enums.AudioSounds audioType)
 {
     return(audioSources.FindAudioByKey(audioType));
 }