Ejemplo n.º 1
0
        private void Awake()
        {
            _carDodgeEventListener.OnEventHappend     += OnCarDodge;
            _carCollisionEventListener.OnEventHappend += OnCarCollision;

            SetVolume(_volume.value);
            _currentPlayer = _menuMusicPlayer;
            _menuMusicPlayer.Play();
        }
Ejemplo n.º 2
0
        private IEnumerator FadeMusicTo(AudioSourcePlayer to)
        {
            if (_currentPlayer == null)
            {
                yield return(StartCoroutine(FadeMusicIn(to)));

                yield break;
            }

            yield return(StartCoroutine(FadeMusicOut(_currentPlayer)));

            StartCoroutine(FadeMusicIn(to));
        }
Ejemplo n.º 3
0
        private IEnumerator FadeMusicOut(AudioSourcePlayer to)
        {
            var timer        = 0f;
            var halfFadeTime = _fadeTime / 2f;

            while (timer < halfFadeTime)
            {
                timer += Time.deltaTime;
                var volume = Mathf.Lerp(_volume.value, 0f, timer / halfFadeTime);
                to.SetVolume(volume);
                yield return(null);
            }
            to.Stop();
        }
Ejemplo n.º 4
0
        private IEnumerator FadeMusicIn(AudioSourcePlayer to)
        {
            if (!to.IsPlaying)
            {
                to.Play();
            }
            if (_currentPlayer == to)
            {
                yield break;
            }
            _currentPlayer = to;

            var timer        = 0f;
            var halfFadeTime = _fadeTime / 2f;

            while (timer < halfFadeTime)
            {
                timer += Time.deltaTime;
                var volume = Mathf.Lerp(0f, _volume.value, timer / halfFadeTime);
                to.SetVolume(volume);
                yield return(null);
            }
        }