Class AudioCuePlayer
- Namespace
- TDMaker.Unity.View
- Assembly
- TDMaker.Unity.dll
Plays AudioCues through a small pool of AudioSources and routes global game events (waves, building,
selling, victory ...) and mechanic events (chains, traps, mines, beams, heals, shields, reflection, knockback, companions,
returning units, body raising) to cues.
Per-template cues (attack, hit, death, projectiles, spells) are routed by EntityViewRegistry; the HUD plays
the interface cues (click, build menu, rally, wave call). Every slot is optional.
Volumes come from TDGameSettings (Master × SFX or UI) and each channel may route to an AudioMixerGroup.
Each cue respects its minInterval, at most Max Voices Per Cue copies play at once and the
pool never grows past Voices (the oldest voice is reused), so dense fights do not stack sounds or allocate.
[AddComponentMenu("2D Tower Defense Maker/Audio Cue Player")]
public sealed class AudioCuePlayer : MonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourAudioCuePlayer
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Constructors
AudioCuePlayer()
public AudioCuePlayer()
Properties
ActiveVoices
Voices currently sounding.
public int ActiveVoices { get; }
Property Value
Cues
Global cue slots.
public AudioCuePlayer.GlobalCues Cues { get; }
Property Value
MasterVolume
Volume of this player, multiplied with the TDGameSettings volumes.
public float MasterVolume { get; set; }
Property Value
MaxVoicesPerCue
Copies of one cue that may sound at once (0 = no limit).
public int MaxVoicesPerCue { get; set; }
Property Value
Mechanics
Mechanic cue slots.
public AudioCuePlayer.MechanicCues Mechanics { get; }
Property Value
Voices
Pooled voices (global voice limit).
public int Voices { get; set; }
Property Value
Methods
Configure(SimulationRunner)
Assigns the runner; call before enabling.
public void Configure(SimulationRunner source)
Parameters
sourceSimulationRunner
EnsureListener(GameObject)
Adds an AudioListener to the main camera (or to fallback) when the scene has no enabled listener, so
cues and music are heard and Unity does not warn every frame. Returns the listener in use.
public static AudioListener EnsureListener(GameObject fallback = null)
Parameters
fallbackGameObject
Returns
- AudioListener
Keyed(string, AudioCue)
The cue registered for key when it has clips, otherwise fallback.
public AudioCue Keyed(string key, AudioCue fallback)
Parameters
Returns
Play(AudioCue)
Plays a 2D gameplay cue (SFX channel).
public void Play(AudioCue cue)
Parameters
cueAudioCue
Play(AudioCue, Vector3)
Plays a gameplay cue at a world position (positional only when the cue's spatial blend is above zero).
public void Play(AudioCue cue, Vector3 position)
Parameters
cueAudioCuepositionVector3
Play(AudioCue, Vector3, AudioChannel)
Plays a cue on a channel: volume = cue × this player × EffectiveVolume(AudioChannel), routed to the channel's mixer group when one is set. Returns false when the cue is empty, silent, throttled by its Min Interval or by the per-cue voice limit.
public bool Play(AudioCue cue, Vector3 position, AudioChannel channel)
Parameters
cueAudioCuepositionVector3channelAudioChannel
Returns
PlayUi(AudioCue)
Plays an interface cue (UI channel).
public void PlayUi(AudioCue cue)
Parameters
cueAudioCue
PlayUi(AudioCue, AudioCue)
Plays preferred when it has clips, otherwise fallback (both on the UI channel).
public void PlayUi(AudioCue preferred, AudioCue fallback)
Parameters
SetKeyedCue(string, AudioCue)
Sets (or with a null cue removes) the cue for a mechanic or status effect id.
public void SetKeyedCue(string key, AudioCue cue)
Parameters
StopAll()
Stops every voice.
public void StopAll()