Exemplo n.º 1
0
 /// <summary>
 /// 背景音乐渐出
 /// </summary>
 public void FadeOutBackgroundMusic()
 {
     if (_backgroundMusic != null)
     {
         _backgroundMusic.FadeInfo = new MusicFadeInfo(MusicFadeType.FadeOut, 0);
         _backgroundMusic          = null;
     }
 }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="audioClip">音频</param>
        public void PlayBackgroundMusic(AudioClip audioClip)
        {
            var musicChannel = CreateAudioChannel();

            musicChannel.Play(audioClip);
            StopBackgroundMusic();
            _backgroundMusic = musicChannel;
        }
Exemplo n.º 4
0
 /// <summary>
 /// 停止背景音乐
 /// </summary>
 public void StopBackgroundMusic()
 {
     if (_backgroundMusic != null)
     {
         _backgroundMusic.Stop();
         _musicChannels.Remove(_backgroundMusic);
         _backgroundMusic = null;
     }
 }
Exemplo n.º 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);
        }