Static helper that provides named audio Mixer instances for the game: Music, Ambience, Sounds, Shelling and Hit. Each getter calls Get(name) which returns an existing mixer by name under the master or creates a child mixer with that name; returns null if the audio master is not available yet.
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;
}
}