Code/GolfMixers.cs

Static utility that provides named audio Mixer instances for the game (music, ambience, sounds, shelling, hit). It finds an existing mixer by name under the master mixer or creates one as a child if missing, and exposes them as static fields.

Native Interop
using Sandbox;
using Sandbox.Audio;

/// <summary>
/// The game's own mixers, one per kind of sound, made under the master mixer the first time they
/// are asked for and found again by name after that (so a hotload or a scene change never makes a
/// second set). Each source sets its handles' TargetMixer to the right one; the guns stay on the
/// default mixer. <see cref="GolfAudioZone"/> filters and ducks these mixers.
/// </summary>
public static class GolfMixers
{
	public const string MusicName = "Golf Music";
	public const string AmbienceName = "Golf Ambience";
	public const string SoundsName = "Golf Sounds";
	public const string ShellingName = "Trench Shelling";
	/// <summary>The distraction hit's ping and ear ring: never muffled, so a hit is always heard.</summary>
	public const string HitName = "Golf Hit";

	public static Mixer Music => Get( MusicName );
	public static Mixer Ambience => Get( AmbienceName );
	public static Mixer Sounds => Get( SoundsName );
	public static Mixer Shelling => Get( ShellingName );
	public static Mixer Hit => Get( HitName );

	/// <summary>The mixer with this name under the master, made if it is not there yet. Null before the audio engine is up.</summary>
	public static Mixer Get( string name )
	{
		var master = Mixer.Master;
		if ( master is null ) return null;

		var mixer = Mixer.FindMixerByName( name );
		if ( mixer is not null ) return mixer;

		mixer = master.AddChild();
		mixer.Name = name;
		return mixer;
	}
}