Ejemplo n.º 1
0
        /// <summary>
        /// 停止播放背景音乐
        /// </summary>
        public void StopBackgroundMusic()
        {
            BackgroundSource.DOKill();

            if (BackgroundSource.isPlaying)
            {
                BackgroundSource.Stop();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="clip">音乐剪辑</param>
        public void PlayBackgroundMusic(AudioClip clip)
        {
            BackgroundSource.DOKill();

            if (BackgroundSource.isPlaying)
            {
                BackgroundSource.Stop();
            }

            BackgroundSource.clip   = clip;
            BackgroundSource.volume = BackgroundVolume;
            BackgroundSource.Play();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="clip">音乐剪辑</param>
        /// <param name="isLoop">是否循环</param>
        /// <param name="speed">播放速度</param>
        public void PlayBackgroundMusic(AudioClip clip, bool isLoop = true, float speed = 1)
        {
            BackgroundSource.DOKill();

            if (BackgroundSource.isPlaying)
            {
                BackgroundSource.Stop();
            }

            BackgroundSource.clip   = clip;
            BackgroundSource.loop   = isLoop;
            BackgroundSource.pitch  = speed;
            BackgroundSource.volume = BackgroundVolume;
            BackgroundSource.Play();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 恢复播放背景音乐
        /// </summary>
        /// <param name="isGradual">是否渐进式</param>
        public void ResumeBackgroundMusic(bool isGradual = true)
        {
            BackgroundSource.DOKill();

            if (isGradual)
            {
                BackgroundSource.volume = 0;
                BackgroundSource.UnPause();
                BackgroundSource.DOFade(BackgroundVolume, 2);
            }
            else
            {
                BackgroundSource.UnPause();
                BackgroundSource.volume = BackgroundVolume;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 暂停播放背景音乐
        /// </summary>
        /// <param name="isGradual">是否渐进式</param>
        public void PauseBackgroundMusic(bool isGradual = true)
        {
            BackgroundSource.DOKill();

            if (isGradual)
            {
                BackgroundSource.DOFade(0, 2).OnComplete(() =>
                {
                    BackgroundSource.Pause();
                    BackgroundSource.volume = BackgroundVolume;
                });
            }
            else
            {
                BackgroundSource.Pause();
                BackgroundSource.volume = BackgroundVolume;
            }
        }