Ejemplo n.º 1
0
 public void AddEventOnEndFade(Action EventOnEndFade)
 {
     if (!IsPlaying)
     {
         OnFadeEnded += new OnFadeEnd(EventOnEndFade);
     }
 }
Ejemplo n.º 2
0
 //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);
         }
     }
 }