예제 #1
0
 /// <summary>
 /// 背景音乐渐出
 /// </summary>
 public void FadeOutBackgroundMusic()
 {
     if (_backgroundMusic != null)
     {
         _backgroundMusic.FadeInfo = new MusicFadeInfo(MusicFadeType.FadeOut, 0);
         _backgroundMusic          = null;
     }
 }
예제 #2
0
        /// <summary>
        /// 背景音乐渐入
        /// </summary>
        /// <param name="audioClip">音频</param>
        public void FadeInBackgroundMusic(AudioClip audioClip)
        {
            var musicChannel = CreateAudioChannel();

            musicChannel.FadeInfo = new MusicFadeInfo(MusicFadeType.FadeIn, _musicVolume);
            FadeOutBackgroundMusic();
            _backgroundMusic = musicChannel;
        }
예제 #3
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="audioClip">音频</param>
        public void PlayBackgroundMusic(AudioClip audioClip)
        {
            var musicChannel = CreateAudioChannel();

            musicChannel.Play(audioClip);
            StopBackgroundMusic();
            _backgroundMusic = musicChannel;
        }
예제 #4
0
 /// <summary>
 /// 停止背景音乐
 /// </summary>
 public void StopBackgroundMusic()
 {
     if (_backgroundMusic != null)
     {
         _backgroundMusic.Stop();
         _musicChannels.Remove(_backgroundMusic);
         _backgroundMusic = null;
     }
 }
예제 #5
0
        /// <summary>
        /// 创建音乐频道
        /// </summary>
        /// <returns></returns>
        public MusicChannel CreateAudioChannel()
        {
            var audioSource = gameObject.AddComponent <AudioSource>();

            audioSource.playOnAwake  = false;
            audioSource.volume       = _musicVolume;
            audioSource.spatialBlend = 0;
            var musicChannel = new MusicChannel(audioSource);

            _musicChannels.Add(musicChannel);
            return(musicChannel);
        }