Example #1
0
 public void FadeInOut(AudioClipEx clip, float durationIn, float durationOut)
 {
     if (clip.clip == _source.clip)
     {
         return;
     }
     StartCoroutine(CoFadeInOut(clip, durationIn, durationOut));
 }
Example #2
0
        public void FadeInSound(AudioClipEx clip, float duration)
        {
            if (clip.clip == _source.clip)
            {
                return;
            }

            StartCoroutine(CoFadeInSound(clip, duration));
        }
Example #3
0
        public void PopInSound(AudioClipEx clip)
        {
            if (clip.clip == _source.clip)
            {
                return;
            }

            _source.Stop();
            _source.SetClipDetails(clip);
            _source.Play();
        }
Example #4
0
        public void FadeInSound(AudioClipEx clip, float duration)
        {
            if (source.isPlaying && clip.clip == source.clip)
            {
                return;
            }

            SetClipDetails(source, clip);
            source.volume = 0f;
            source.Play();

            source.DOFade(clip.volume, duration).Play();
        }
Example #5
0
 private void SetClipDetails(AudioSource source, AudioClipEx clip)
 {
     source.clip   = clip.clip ?? source.clip;
     source.volume = clip.volume;
     source.outputAudioMixerGroup = clip.mixer ?? source.outputAudioMixerGroup;
     source.loop = clip.Loop;
     if (clip.VaryPitch)
     {
         var factor = RandomEx.Range(clip.PitchFactor);
         source.pitch = factor;
     }
     else
     {
         source.pitch = 1;
     }
 }
Example #6
0
        public void CorssfadeToSound(AudioClipEx clip, float durationIn, float durationOut)
        {
            if (source.isPlaying && clip.clip == source.clip)
            {
                return;
            }

            Sequence seq = DOTween.Sequence().Append(source.DOFade(0, durationOut).OnComplete(() =>
            {
                source.Stop();
                SetClipDetails(source, clip);
                source.volume = 0;
                source.Play();
            })).Append(source.DOFade(clip.volume, durationIn));

            seq.Play();
        }
Example #7
0
        private IEnumerator CoFadeInSound(AudioClipEx clip, float duration)
        {
            _source.SetClipDetails(clip);
            _source.volume = 0f;
            _source.Play();

            var start = Time.time;
            var end   = start + duration;

            while (Time.time < end)
            {
                _source.volume = Tween.Lerp(0, clip.volume, (Time.time - start) / duration);
                yield return(null);
            }

            _source.volume = clip.volume;
        }
Example #8
0
 public static void SetClipDetails(this AudioSource source, AudioClipEx clipEx)
 {
     source.clip   = clipEx.clip ?? source.clip;
     source.volume = clipEx.volume;
     source.outputAudioMixerGroup = clipEx.mixer ?? source.outputAudioMixerGroup;
 }
Example #9
0
 public void PopInSound(AudioClipEx clip)
 {
     source.Stop();
     SetClipDetails(source, clip);
     source.Play();
 }
Example #10
0
        private IEnumerator CoFadeInOut(AudioClipEx clip, float durationIn, float durationOut)
        {
            yield return(StartCoroutine(CoFadeOutSound(durationOut)));

            yield return(StartCoroutine(CoFadeInSound(clip, durationIn)));
        }