Basic Pipeline

Updated 6 months ago

Usage

Basic Pipeline

  1. Open a BepInEx BaseUnityPlugin
  2. 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
  3. 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 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"]
  4. 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);
    • 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);
    • Now, add all your sounds to the AudioList, for example ones loaded from an AssetBundle
      • SharedAudioMethods.AudioClipAddNewRange(AssetBundle.LoadAllAssets<AudioClip>(), yourList);
  5. 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)
  6. Now, use the "AudioClipGet" methods to call whatever AudioClip you want the item to play
    • For example, use AudioClipGetRandom() for random sounds, or AudioClipGetNextInAudioList() to play sounds in order, like a playlist
    • Then write to the AudioItem's object with __instance.clipToPlay = SharedAudioMethods.AudioClipGetRandom(yourList);

And that's it, the item now calls a random AudioClip from your AudioList!