GameMode/Voice/PlayerVoiceComponent.cs

A player voice component derived from the engine Voice class. It finds a voice filter component in the scene and sets the audio mixer to the "Voice" mixer, and delegates exclusion logic to any discovered IVoiceFilter.

using Sandbox.Audio;

namespace KOTH;

public partial class PlayerVoiceComponent : Voice
{
	[Property] public PlayerState PlayerState { get; set; }

	IVoiceFilter Filter { get; set; }

	protected override void OnStart()
	{
		Filter = Scene.GetAllComponents<IVoiceFilter>().FirstOrDefault();
		TargetMixer = Mixer.FindMixerByName("Voice");
	}

	protected override IEnumerable<Connection> ExcludeFilter()
	{
		if (Filter is null) return base.ExcludeFilter();
		return Filter.GetExcludeFilter();
	}
}