コード例 #1
0
 public void PlayMusic(int id)
 {
     if (UltimaGameSettings.Audio.MusicOn)
     {
         if (id < 0) // not a valid id, used to stop music.
         {
             StopMusic();
             return;
         }
         if (!_music.ContainsKey(id))
         {
             string name;
             bool   loops;
             if (MusicData.TryGetMusicData(id, out name, out loops))
             {
                 _music.Add(id, new UOMusic(id, name, loops));
             }
             else
             {
                 Utils.Error($"Received unknown music id {id}");
                 return;
             }
         }
         var toPlay = _music[id];
         if (toPlay != _musicCurrentlyPlaying)
         {
             // stop the current song
             StopMusic();
             // play the new song!
             _musicCurrentlyPlaying = toPlay as UOMusic;
             _musicCurrentlyPlaying.Play(false);
         }
     }
 }
コード例 #2
0
 public void StopMusic()
 {
     if (_musicCurrentlyPlaying != null)
     {
         _musicCurrentlyPlaying.Stop();
         _musicCurrentlyPlaying.Dispose();
         _musicCurrentlyPlaying = null;
     }
 }