コード例 #1
0
        public void Play(string musicName, bool loopTrack = true)
        {
            if (IsPlaying)
            {
                Stop();
            }

            CurrentMusicName = Exceptions(musicName);
            CurrentMusic?.Play(Volume, loopTrack);
        }
コード例 #2
0
 protected override void Update()
 {
     base.Update();
     if (musicList.Count > 1)
     {
         //需要维护队列
         if (CurrentMusic && !CurrentMusic.isPlaying)
         {
             CurrentMusic.Stop();
             musicList.Remove(CurrentMusic);
             Destroy(CurrentMusic);
             CurrentMusic = musicList[0];
             CurrentMusic.Play();
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// 播放背景音乐
 /// </summary>
 /// <param name="abName">名字</param>
 /// <param name="loop">是否循环</param>
 /// <param name="isTrack">是否音轨</param>
 public void PlayMusic(string abName, string assetname, bool loop = true, bool isTrack = false)
 {
     if (!isTrack)
     {
         if (CurrentMusic && CurrentMusic.clip.name == assetname)
         {
             CurrentMusic.time = 0;
             CurrentMusic.Play();
         }
         else
         {
             if (musicList.Count != 0)
             {
                 foreach (var source in musicList)
                 {
                     if (source.clip.name == assetname)
                     {
                         CurrentMusic = source;
                         CurrentMusic.Play();
                     }
                     else
                     {
                         source.Stop();
                     }
                 }
             }
         }
     }
     else
     {
         foreach (var source in musicList)
         {
             if (source.clip.name == assetname)
             {
                 source.Play();
             }
             else
             {
                 source.Stop();
             }
         }
     }
 }