public void AddEventOnEndFade(Action EventOnEndFade) { if (!IsPlaying) { OnFadeEnded += new OnFadeEnd(EventOnEndFade); } }
//coroutines IEnumerator FadeRoutine(AudioSource source, float end, float time, OnFadeEnd onFadeEnd = null) { if (time <= 0) { source.volume = end; } else { float start = source.volume; float currentTime = 0f; if (start == end) { //do nothing } else { while (source.volume != end) { source.volume = Mathf.Lerp(start, end, currentTime); currentTime += Time.deltaTime / time; yield return(null); } source.volume = end; if (onFadeEnd != null) { onFadeEnd.Invoke(source); } } } }
//coroutines IEnumerator FadeRoutine(AudioSource source, float end, float time, OnFadeEnd onFadeEnd = null) { if (time <= 0) { source.volume = end; } else { float start = source.volume; float currentTime = 0f; if (start == end) { //do nothing } else { while (source.volume != end) { source.volume = Mathf.Lerp (start, end, currentTime); currentTime += Time.deltaTime / time; yield return null; } source.volume = end; if(onFadeEnd != null) onFadeEnd.Invoke (source); } } }