Example #1
0
 public virtual void ResumeMusic()
 {
     if (CurrentMusicAudioSource != null && MusicVolume > 0)
     {
         CurrentMusicAudioSource.Play();
     }
 }
Example #2
0
        private void DoMusicPlay(AudioClip musicClip, float startVolume, float endVolume)
        {
            GDebug.Log("playing music: " + musicClip.name, this, LogCategory.SOUND_MANAGER);

            if (CurrentMusicAudioSource != null)
            {
                CurrentMusicAudioSource.clip   = musicClip;
                CurrentMusicAudioSource.volume = startVolume;

                if (!_muteMusic)
                {
                    CurrentMusicAudioSource.Play();
                }

                DOTween.Kill(_musicFadeOutTweener);

                _musicFadeInTweener = DOTween.To(() => CurrentMusicAudioSource.volume, (val) => CurrentMusicAudioSource.volume = val, endVolume, FadeTime).SetEase(Ease.InCubic);
            }
        }
Example #3
0
        public void FadeMusic(float volume, float duration)
        {
            // currentMusicAudioSource may be null
            if (CurrentMusicAudioSource == null)
            {
                return;
            }

            if (_muteMusic)
            {
                CurrentMusicAudioSource.Pause();
                return;
            }

            if (!CurrentMusicAudioSource.isPlaying)
            {
                CurrentMusicAudioSource.Play();
            }

            if (_musicFadeOutTweener != null)
            {
                _musicFadeOutTweener.Kill();
            }

            if (duration <= 0)
            {
                CurrentMusicAudioSource.volume = volume;
                if (volume < .1f)
                {
                    CurrentMusicAudioSource.Pause();
                }
            }
            else
            {
                _musicFadeOutTweener = DOTween.To(() => CurrentMusicAudioSource.volume, (val) => CurrentMusicAudioSource.volume = val, volume, duration).OnComplete(() => this.DoneMusicFade(CurrentMusicAudioSource));
            }
        }