Beispiel #1
0
    private IEnumerator EndMix(float duration, float previousMusicTime, PossibleMusics previousMusicName)
    {
        Debug.Log("Waiting: " + duration);
        yield return(new WaitForSeconds(duration));

        Debug.Log("Back from mix");
        PlayMusic(previousMusicName, previousMusicTime);
    }
Beispiel #2
0
    public static void MixMusic(PossibleMusics newMusicName)
    {
        if (Instance == null)
        {
            Debug.LogWarning("No hay instancia de AudioManager");
            return;
        }
        // si volviera del silencio volvería a la música anterior, así que
        // no se almacena nada

        if (IsMusicOptionEnable())
        {
            AudioSource newMusic;
            if (musicAudioSources.ContainsKey(newMusicName))
            {
                // si existe la nueva música, obtiene una referencia
                newMusic = musicAudioSources [newMusicName];
                if (newMusic != current)
                {
                    // if(current)
                    // {
                    //  // se llama a la corrutina para que vuelva a la música cuando acabe
                    //     Instance.StartCoroutine(Instance.EndMix(newMusic.clip.length, current.time, _lastMusicName));
                    // }
                    // empieza a sonar la música del mix
                    if (current != null)
                    {
                        PlayMusic(newMusicName, current.time);
                    }
                    else
                    {
                        PlayMusic(newMusicName);
                    }

                    // Debug.Log ("Now mixing: " + newMusicName);
                }
                else
                {
                    Debug.Log("Same music, not mixing: " + newMusicName);
                }
            }
            else
            {
                Debug.Log("Music unknown for mix: " + newMusicName);
            }
        }
        else
        {
            Debug.Log("Music is off, not playing mix: " + newMusicName);
        }
    }
Beispiel #3
0
    public static void PlayMusic(PossibleMusics newMusicName, float newMusicTime = 0f)
    {
        if (Instance == null)
        {
            Debug.LogWarning("No hay instancia de AudioManager");
            return;
        }
        // almacena la música solicitada por si hubiera que volver del silencio
        _lastMusicName = newMusicName;

        if (IsMusicOptionEnable())
        {
            AudioSource newMusic;
            if (musicAudioSources.ContainsKey(newMusicName))
            {
                // si existe la nueva música, obtiene una referencia
                newMusic = musicAudioSources [newMusicName];
                if (newMusic != current)
                {
                    Instance.StopCoroutine("FadeIn");
                    Instance.StopCoroutine("FadeOut");
                    // establece el tiempo de inicio de la nueva música (normalmente 0 a no ser que se vuelva de un mix)
                    newMusic.time = newMusicTime;
                    // si no es la que está ya sonando hace un cross fade
                    if (current)
                    {
                        Instance.StartCoroutine(Instance.FadeOut(current));
                    }

                    Instance.StartCoroutine(Instance.FadeIn(newMusic));
                    // Debug.Log ("AudioManager: Now playing: " + newMusicName);
                }
                else
                {
                    Debug.Log("AudioManager: Same music, not restarting: " + newMusicName);
                }
            }
            else
            {
                Debug.Log("AudioManager: Music unknown: " + newMusicName);
            }
        }
        else
        {
            Debug.Log("AudioManager: Music is off, not playing: " + newMusicName);
        }
    }