Beispiel #1
0
 internal static void ResizeAndFillArrays()
 {
     customSounds         = new SoundEffect[nextSound[SoundType.Custom]];
     customSoundInstances = new SoundEffectInstance[nextSound[SoundType.Custom]];
     Array.Resize(ref Main.soundItem, nextSound[SoundType.Item]);
     Array.Resize(ref Main.soundInstanceItem, nextSound[SoundType.Item]);
     Array.Resize(ref Main.soundNPCHit, nextSound[SoundType.NPCHit]);
     Array.Resize(ref Main.soundInstanceNPCHit, nextSound[SoundType.NPCHit]);
     Array.Resize(ref Main.soundNPCKilled, nextSound[SoundType.NPCKilled]);
     Array.Resize(ref Main.soundInstanceNPCKilled, nextSound[SoundType.NPCKilled]);
     Array.Resize(ref Main.music, nextSound[SoundType.Music]);
     Array.Resize(ref Main.musicFade, nextSound[SoundType.Music]);
     foreach (SoundType type in Enum.GetValues(typeof(SoundType)))
     {
         foreach (string sound in sounds[type].Keys)
         {
             int slot = GetSoundSlot(type, sound);
             if (type != SoundType.Music)
             {
                 GetSoundArray(type)[slot]         = ModContent.GetSound(sound);
                 GetSoundInstanceArray(type)[slot] = GetSoundArray(type)[slot]?.CreateInstance() ?? null;
             }
             else
             {
                 Main.music[slot] = ModContent.GetMusic(sound) ?? null;
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Adds the given sound file to the game as the given type of sound and with the given custom sound playing. If no ModSound instance is provided, the custom sound will play in a similar manner as the default vanilla ones.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="soundPath">The sound path.</param>
        /// <param name="modSound">The mod sound.</param>
        public void AddSound(SoundType type, string soundPath, ModSound modSound = null)
        {
            if (!loading)
            {
                throw new Exception("AddSound can only be called from Mod.Load or Mod.Autoload");
            }

            int id = SoundLoader.ReserveSoundID(type);

            SoundLoader.sounds[type][soundPath] = id;

            if (modSound != null)
            {
                SoundLoader.modSounds[type][id] = modSound;

                modSound.Sound = ModContent.GetSound(soundPath);
            }
        }