Add settings menu to control audio and return to main menu

This commit is contained in:
Ben Calegari 2026-07-28 22:01:28 -07:00
parent c88d3fc625
commit 0b7bc936ef
13 changed files with 697 additions and 22 deletions

View file

@ -11,6 +11,12 @@ namespace TD.Audio
{
public AudioCategory category;
public int maxVoices;
// NOTE: currently inert. It seeds each pooled AudioSource at init, but every
// Play() call overwrites src.volume with (per-sound volume × SFX slider), so
// this value never reaches the mix. Left as-is rather than "fixed" because
// multiplying it in would halve every existing sound (authored scenes use 0.5).
// Wire it up only alongside a pass to re-level the per-sound volumes.
[Range(0f, 1f)]
public float volume;
}
@ -58,6 +64,16 @@ namespace TD.Audio
}
}
/// <summary>
/// Plays a one-shot on the given category's voice pool. <paramref name="volume"/> is
/// the per-sound authored level; it's scaled by the player's SFX slider
/// (<see cref="AudioVolumeSettings.SfxScalar"/>) on the way in.
/// </summary>
/// <remarks>
/// The scalar is sampled at play time, so a sound already in flight keeps the volume
/// it started with when the slider moves. Every SFX here is short, so that's
/// imperceptible and avoids having to track live voices.
/// </remarks>
public void Play(AudioClip clip, AudioCategory category, float pitch = 1f, float volume = 1f)
{
if (clip == null) return;
@ -66,7 +82,7 @@ namespace TD.Audio
int idx = indices[category];
var src = pool[idx % pool.Length];
src.pitch = pitch;
src.volume = volume;
src.volume = volume * AudioVolumeSettings.SfxScalar;
src.clip = clip;
src.Play();
indices[category] = idx + 1;