Beispiel #1
0
    public void FadeInTrackOverSeconds(MusicManager.Track trackID, float duration)
    {
        musicSource.volume = 0.0f;

        PlayTrack(trackID);
        StartCoroutine(FadeInTrackOverSecondsCoroutione(duration));
    }
Beispiel #2
0
    public void PlayTrack(MusicManager.Track trackID, float fadeDuration = 1)
    {
        musicSource.clip = trackList[(int)trackID];
        musicSource.Play();

        StartCoroutine(FadeInTrackOverSecondsCoroutione(fadeDuration));
    }
 /// <summary>
 /// fade out from current track and fade into the new track over a specified duration
 /// </summary>
 /// <param name="trackID"></param>
 /// <param name="duration"></param>
 public void FadeOutAndInTrack(MusicManager.Track trackID, float duration)
 {
     //if coroutine is running
     if (FadingOutAndInTrack != null)
     {
         StopCoroutine(FadingOutAndInTrack);
     }
     FadingOutAndInTrack = FadeOutAndInOverSecondsCoroutine(trackID, duration);
     StartCoroutine(FadingOutAndInTrack);
 }
 /// <summary>
 /// change to a new track and fade in to it
 /// </summary>
 /// <param name="trackID"></param>
 /// <param name="duration"></param>
 public void FadeInTrackOverSeconds(MusicManager.Track trackID, float duration)
 {
     //if coroutine is running
     if (FadingInTrack != null)
     {
         StopCoroutine(FadingInTrack);
     }
     musicSource.clip = trackList[(int)trackID];
     musicSource.Play();
     FadingInTrack = FadeInOverSecondsCoroutine(duration);
     StartCoroutine(FadingInTrack);
 }
    /// <summary>
    /// coroutine that fades out the track and then switchs to the new track
    /// </summary>
    /// <param name="trackID"></param>
    /// <param name="duration"></param>
    /// <returns></returns>
    IEnumerator FadeOutAndInOverSecondsCoroutine(MusicManager.Track trackID, float duration)
    {
        var   initialVolume = musicSource.volume;
        float timer         = 0.0f;

        while (timer < duration)
        {
            timer += Time.deltaTime;
            float normalizedTime = timer / duration;

            musicSource.volume = Mathf.SmoothStep(initialVolume, 0, normalizedTime);;
            //fade volume
            yield return(new WaitForEndOfFrame());
        }
        //switch to new track and fade into it
        FadeInTrackOverSeconds(trackID, duration);
    }
Beispiel #6
0
    IEnumerator FadeOutAndInTrackOverSecondsCoroutine(MusicManager.Track fadeInTrackID, float duration)
    {
        float timer = duration;

        //Fade out
        while (timer >= 0.0f)
        {
            //Debug.Log("Fade out");
            timer -= Time.deltaTime;

            float normalizedTime = timer / duration;

            musicSource.volume = normalizedTime;

            yield return(new WaitForEndOfFrame());
        }

        //Fade in new track
        FadeInTrackOverSeconds(fadeInTrackID, duration);
    }
 /// <summary>
 /// play a specific clip based on its trackID
 /// </summary>
 /// <param name="trackID"></param>
 public void PlayTrack(MusicManager.Track trackID)
 {
     musicSource.clip = trackList[(int)trackID];
     musicSource.Play();
 }
 public void FadeInTrackOverSeconds(MusicManager.Track trackID, float duration)
 {
     PlayTrack(trackID);
     StartCoroutine(FadeInTrackOverSecondsCoroutine(duration));
 }