Beispiel #1
0
        public static Music GetTrack(string TrackName, string ModName = null)
        {
            if (TrackName == null || Main.engine == null)
            {
                return(null);
            }
            if (ModName == null)
            {
                ModName = TMod.GetCurrentMod();
            }
            if (!AudioBank.BanksDict.TryGetValue(ModName, out IList <AudioBank> value))
            {
                return(null);
            }
            Audio audio = null;

            foreach (AudioBank item in value)
            {
                audio = item.GetTrack(TrackName);
                if (audio != null)
                {
                    break;
                }
            }
            if (audio == null)
            {
                return(GetLegacyTrack(TrackName));
            }
            return((Music)audio);
        }
Beispiel #2
0
            public static void FadeTo(string SongName, float FadeTime = 3f, Priorities SongPriority = Priorities.None)
            {
                if (Main.dedServ || Main.engine == null || SongPriority < Priority)
                {
                    return;
                }
                Priority = SongPriority;
                string text = Config.tempModAssembly + "\\" + TMod.GetCurrentMod() + "\\" + SongName;

                if (!Path.HasExtension(text))
                {
                    string text2 = text + ".mp3";
                    text = ((!File.Exists(text2)) ? (text + ".wav") : text2);
                }
                if (SongName == null || File.Exists(text))
                {
                    NextSong       = text;
                    MusicFadeDelay = FadeTime;
                    FadingOut      = true;
                    if (FadingIn)
                    {
                        FadingIn   = false;
                        MusicTimer = MusicFadeDelay - MusicTimer;
                    }
                }
            }
Beispiel #3
0
 public static void Play(string SongName, Priorities SongPriority = Priorities.None, bool Repeat = true)
 {
     if (Main.dedServ || Main.engine == null || SongPriority < Priority)
     {
         return;
     }
     if (FadingIn)
     {
         MediaPlayer.Volume = GameVolume;
     }
     FadingIn  = false;
     FadingOut = false;
     Stop(Priority);
     Priority = SongPriority;
     if (CurrentSong != null)
     {
         CurrentSong.Dispose();
         CurrentSong = null;
     }
     if (SongName != null)
     {
         string text = (!Path.IsPathRooted(SongName)) ? (Config.tempModAssembly + "\\" + TMod.GetCurrentMod() + "\\" + SongName) : SongName;
         if (!Path.HasExtension(text))
         {
             string text2 = text + ".mp3";
             text = ((!File.Exists(text2)) ? (text + ".wav") : text2);
         }
         if (File.Exists(text) && GameVolume > 0f)
         {
             CurrentSong             = LoadSong("", text, 0);
             MediaPlayer.IsRepeating = Repeat;
             MediaPlayer.Play(CurrentSong);
             IsPlaying        = true;
             Main.musicVolume = 0f;
         }
         else
         {
             Priority = Priorities.None;
         }
     }
 }