Beispiel #1
0
        private void CrossFadeClip(AudioClip clip, float volume)
        {
            if (_secondarySource == null)
            {
                CreateSecondarySource();
                // we're probably coming from not being a cross fader
                _primarySource.GetCallback().OnStop.RemoveListener(OnSourceStop);
            }

            AudioSource fadeOutSource;
            AudioSource fadeInSource;

            if (_currentSource == _primarySource && _currentSource.isPlaying)
            {
                fadeOutSource = _primarySource;
                fadeInSource  = _secondarySource;
            }
            else
            {
                fadeOutSource = _secondarySource;
                fadeInSource  = _primarySource;
            }

            fadeOutSource.FadeOut(CrossFadeDuration);

            fadeInSource.clip = clip;
            fadeInSource.FadeIn(CrossFadeDuration, volume);

            _currentSource = fadeInSource;

            _timeUntilFade = -FindTimeUntilFade(clip);
        }