Basic Pipeline
Updated 5 months agoUsage
Basic Pipeline
- Open a BepInEx BaseUnityPlugin
- Find this library's .dll file on your computer
- Can be found in Thunderstore's
Settings > Browse profile folder > BepInEx > plugins > SimonTendo-STSharedAudioLib > STSharedAudioLib.dll
- Copy the path to this folder, in the file explorer's top bar
- Can be found in Thunderstore's
- Reference the assembly in your plugin
- In the plugin's project settings:
- In the References, add
<Reference Include="STSharedAudioLib.dll" HintPath="PathYouJustCopied\STSharedAudioLib.dll" />
- In the References, add
- In the namespace's Using field
using STSharedAudioLib;
- In the main Plugin Class:
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInDependency("STSharedAudioLib")]
- In the plugin manifest's dependencies:
"dependencies": ["BepInEx-BepInExPack-5.4.2100", "SimonTendo-STSharedAudioLib-0.0.1"]
- In the plugin's project settings:
- First, add the SharedAudioComponent to the object you want to add sounds to
- For example, an object from the game's AllObjectsList
- You could first reference the object with
GameObject yourObject = AllObjectsList.AudioItems[0];
- Then add the component with
SharedAudioComponent yourComponent = SharedAudioMethods.GetSharedAudioComponent(yourObject);
- You could first reference the object with
- By default, a new AudioList will be added to the new SharedAudioComponent, this is where AudioClips go
- Get the list with
AudioList yourList = SharedAudioMethods.AudioListGetDefault(yourComponent);
- Get the list with
- Now, add all your sounds to the AudioList, for example ones loaded from an AssetBundle
SharedAudioMethods.AudioClipAddNewRange(AssetBundle.LoadAllAssets<AudioClip>(), yourList);
- For example, an object from the game's AllObjectsList
- Next, patch the object you want to play the sounds on at the moment the sound is called
- For example, before a method called PlayAudio is called
[HarmonyPrefix, HarmonyPatch(typeof(AudioItem), "PlayAudio")]
public static void Prefix(AudioItem __instance)
- For example, before a method called PlayAudio is called
- Now, use the "AudioClipGet" methods to call whatever AudioClip you want the item to play
- For example, use
AudioClipGetRandom()
for random sounds, orAudioClipGetNextInAudioList()
to play sounds in order, like a playlist - Then write to the AudioItem's object with
__instance.clipToPlay = SharedAudioMethods.AudioClipGetRandom(yourList);
- For example, use
And that's it, the item now calls a random AudioClip from your AudioList!