Exemplo n.º 1
0
    public IEnumerator PlayingMusic(MusicSO music)
    {
        MusicSources[music.MusicID] = new List <AudioSource>();

        foreach (ClipSO clip in music.MainLines)
        {
            AudioSource audio = SetupAudioMusic(clip);
            MusicSources[music.MusicID].Add(audio);
        }

        if (music.BarsToWait[0])
        {
            yield return(new WaitForSeconds(music.MainLines[0].clip.length));
        }

        foreach (ClipSO clip in music.MelodicLines)
        {
            AudioSource audio = SetupAudioMusic(clip);
            MusicSources[music.MusicID].Add(audio);
        }

        if (music.BarsToWait[1])
        {
            yield return(new WaitForSeconds(music.MelodicLines[0].clip.length));
        }

        foreach (ClipSO clip in music.AccompanimentLines)
        {
            AudioSource audio = SetupAudioMusic(clip);
            MusicSources[music.MusicID].Add(audio);
        }
    }
Exemplo n.º 2
0
    // MUSICS
    public void PlayMusic(MusicNames musicID)
    {
        if (_selectedMusic != null)
        {
            StopMusic();
            _finishingMusic = _selectedMusic;
        }
        _selectedMusic = Musics.Find(music => music.MusicID == musicID);
        if (_selectedMusic == null)
        {
            Debug.LogError("The music to play has not been found -- " + musicID);
            return;
        }
        if (MusicSources.ContainsKey(musicID))
        {
            Debug.LogWarning("The music is already being played -- " + musicID);
            return;
        }

        if (_finishingMusic != null)
        {
            StartCoroutine(FadeMixerGroup.StartFade(AudioMixer, "Fading", FadingTime, -40f));
            StartCoroutine(ChangePlayingMusic());
        }
        else
        {
            _musicCoroutine = StartCoroutine(PlayingMusic(_selectedMusic));
        }
    }
Exemplo n.º 3
0
    public IEnumerator StoppingMusic()
    {
        yield return(new WaitForSeconds(FadingTime));

        if (_finishingMusic != null && MusicSources.ContainsKey(_finishingMusic.MusicID))
        {
            for (int i = 0; i < MusicSources[_finishingMusic.MusicID].Count; i++)
            {
                AudioSource audio = MusicSources[_finishingMusic.MusicID][i];
                Destroy(audio.gameObject);
            }
            MusicSources[_finishingMusic.MusicID].Clear();

            MusicSources.Remove(_finishingMusic.MusicID);
            _finishingMusic = null;
        }

        AudioMixer.SetFloat("Fading", MusicVolume);
    }