Loading a sound file from disk
Updated 8 months agoWhat can you do with this?
This part of LCSoundTool allows you to load any sound of your choosing from your mod's or any specified directory from the file system. This could be used for your mod instead of other audio loading methods, if as an example you want users to be able to customize the sounds used in your mod easily or as a simple and convinient way to load audio files.
How do I make my sound files?
LCSoundTool supports and works best with 44100 Hz sample rate audio files with either a 16 bit PCM Wav files (.wav), Ogg Vorbis files (.ogg) or Mpeg Mp3 files (.mp3). If you are having troubles with your audio not playing in the game or it is silent, I recommend you redo the audio file to make sure it is properly formatted for this mod.
I recommend you avoid online audio file converters if you're changing file types as they can cause issues with my mod. If you have a need to convert a format or otherwise edit an existing audio file, I highly recommend the free and open source program called Audacity.
Loading the sound
Remember to check out some basic tutorials for BepInEx mods first, but this should be fairly easy to follow. First of all, to be able to use any part of LCSoundTool, you want to add using LCSoundTool;
to the top of your CSharp file. Most LCSoundTool functionality can be accessed through the SoundTool
class. Here is some basic pseudo code that loads an AudioClip to variable called newSound
which can then be used by your mod.
using LCSoundTool;
AudioClip newSound;
newSound = SoundTool.GetAudioClip("YourModDirectory", "SubFolder", "test.wav");
With this code we are using the SoundTool.GetAudioClip()
method to load our audio clip from the file system. The variables it takes in are YourModDirectory
which is the name of the folder your mod is installed in inside the plugins folder. Mod managers create this usually as "Author-ModName". As an example, this mod is installed as "no00ob-LCSoundTool". The second variable SubFolder
is an optional folder inside the YourModDirectory
where your sound files are located. You could have your sounds inside something like the following structure: "no00ob-EpicCustomSound\Sounds". This variable is completely optional and can be left out if you do not want a sub folder. Setup like this would work as well if you do not want a sub folder.
newSound = SoundTool.GetAudioClip("YourModDirectory", "test.wav");
The last variable test.wav
in this case is finally the audio file we are loading. This of course supports 3 different file types as specified earlier. It could be test.ogg
or test.mp3
for an example.