Mod Loader/Reference/Purchase sound API
Appearance
The shop plays one sound after a successful fabric or accessory purchase and another when the player cannot afford it. This API changes those two sound banks; it does not change the soundtrack.
Add a sound
Wait for the sound controller before accessing its clips. The example removes one original success clip and registers a replacement from an AssetBundle.
using System;
using System.IO;
using BepInEx;
using DressmakerMods;
using UnityEngine;
[BepInPlugin("example.shop-audio", "Shop Audio", "1.0.0")]
[BepInDependency("yuu.dressmaker.mods", "0.6.71")]
public sealed class ShopAudio : BaseUnityPlugin
{
private IDisposable ready;
private IDisposable hidden;
private IDisposable added;
private AssetBundle bundle;
private void Start()
{
bundle = AssetBundle.LoadFromFile(
Path.Combine(Paths.PluginPath, "ShopAudio", "sounds"));
ready = PurchaseSoundModApi.WhenReady(() =>
{
AudioClip[] originals = PurchaseSoundModApi.GetOriginalClips(PurchaseSound.Success);
if (originals.Length > 0)
hidden = PurchaseSoundModApi.SuppressClip(PurchaseSound.Success, originals[0]);
AudioClip clip = bundle?.LoadAsset<AudioClip>("Buy");
if (clip != null)
added = PurchaseSoundModApi.AddClip(
PurchaseSound.Success, "example.shop-audio.buy", clip);
});
}
private void OnDestroy()
{
ready?.Dispose();
added?.Dispose();
hidden?.Dispose();
bundle?.Unload(false);
}
}
Methods and values
PurchaseSound.Success- Sound played when the purchase succeeds.
PurchaseSound.NotEnoughGold- Sound played when the player cannot afford the purchase.
bool IsReady- True after the sound controller is ready.
IDisposable WhenReady(Action callback)- Runs the callback when the sound controller is ready, or immediately if it already is. Dispose to cancel a callback that has not run yet.
AudioClip[] GetOriginalClips(PurchaseSound sound)- Returns a copy of the game's original clips for that outcome.
AudioClip[] GetClips(PurchaseSound sound)- Returns a copy of the clips currently available for that outcome.
IDisposable AddClip(PurchaseSound sound, string id, AudioClip clip)- Adds a clip to the bank. IDs must be unique across loaded plugins. Dispose the handle to remove it.
bool RemoveClip(PurchaseSound sound, string id)- Removes a clip registered through this API. Returns
falseif the ID is unknown. IDisposable SuppressClip(PurchaseSound sound, AudioClip clip)- Hides a clip until the handle is disposed. Keep one handle for each original clip you suppress.
If every clip in a bank is suppressed, that purchase outcome is silent. Keep custom clips and their AssetBundle loaded while registered.