Example #1
0
 public void ChapterThreeBGMPlay()
 {
     if (!audioSourceTwo.isPlaying)
     {
         StartCoroutine(AudioFadeController.FadeIn(audioSourceTwo, fadeTimer));
     }
     else
     {
         StartCoroutine(AudioFadeController.FadeOut(audioSourceTwo, fadeTimer));
     }
 }
Example #2
0
 public void ChapterTwoBGMPlay()
 {
     if (!audioSourceOne.isPlaying)
     {
         StartCoroutine(AudioFadeController.FadeIn(audioSourceOne, fadeTimer));
         isPlay = true;
     }
     else
     {
         StartCoroutine(AudioFadeController.FadeOut(audioSourceOne, fadeTimer));
         isPlay = false;
     }
 }
    IEnumerator StopSoundClipCor(AudioSource source, float fadeTime, float finalVolume, float delay)
    {
        if (delay > 0f)
        {
            yield return(new WaitForSeconds(delay));
        }
        if (_fadeControllers.ContainsKey(source) == false)
        {
            yield break;
        }
        AudioFadeController controller = _fadeControllers[source];

        if (controller.fading)
        {
            // we're already fading, so stop the current one
            controller.fading = false;
            yield return(1);
        }
        controller.fading = true;

        float time        = 0f;
        float t           = 0f;
        float startVolume = source.volume;

        while (t < 1f && source.isPlaying && controller.fading)
        {
            time         += Time.deltaTime;
            t             = time / fadeTime;
            source.volume = Mathf.Lerp(startVolume, finalVolume, t);
            yield return(1);
        }

//		if (_fadingAudioSources.Contains(source)) {
//			_fadingAudioSources.Remove(source);
//		}

        if (finalVolume == 0f && controller.fading)
        {
            if (source.isPlaying)
            {
                source.Stop();
            }
        }

        controller.fading = false;
    }