AudioManager
A class in Root.Township, the global namespace.
Plays Wwise sound effects, one shot at a point, on an object, or on a given Wwise game object. Muted and disabled on a headless server. Get it with SingletonBehaviour<AudioManager>.Instance.
- Listed in Global namespace: A to B
- Inherits or implements
SingletonBehaviour<AudioManager> - Derived types
AudioManager
Constructors
| Member | What it is |
|---|---|
AudioManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
9 private and internal fields
| Member | What it is |
|---|---|
private SoundEffectsMap currentSoundEffectsMapping | Map from old SoundEffect enum values to sound sets, used by Resolve as a fallback. |
private bool isIgnoringMultipleCallsInSameFrame | If true, the same caller can play a given sound set only once per frame. |
private bool isMuted | Backing field for IsMuted. |
private bool isSoundDisabledOnServer | If true, starting a server suspends Wwise and mutes. |
private static Logger logger | NLog logger for this class. |
private Dictionary<SoundEffectSet, HashSet<int>> soundEffectCallerIds | Per sound set, the caller instance ids that played it this frame. |
private static SimpleAudioControl staticAudioControl | Shared control object reused for uncontrolled plays. |
private PooledObjectDefinition tempWwiseAudioDefinition | Pooled object definition for temporary Wwise emitters used by one-shot sounds. |
private Task waitForLoad | Task that completes once Wwise is ready. |
Properties
| Member | What it is |
|---|---|
bool IsMuted { get; private set; } | True while sound is suspended, for example after the server starts. |
Events
| Member | What it is |
|---|---|
event AudioMuteEvent AudioMutedEvent | Raised when IsMuted changes. |
Methods
| Member | What it is |
|---|---|
void PlaySoundEffect(SoundEffectSet soundEffect, GameObject caller, params ISoundProperty[] soundProperties) | Plays a sound effect set on a pooled temporary emitter or a given Wwise object. The out overloads return an AudioControl to stop or change it. |
void PlaySoundEffect(SoundEffectSet soundEffect, AkGameObj akGameObj, GameObject caller, params ISoundProperty[] soundProperties) | Plays a sound effect set on a pooled temporary emitter or a given Wwise object. The out overloads return an AudioControl to stop or change it. |
void PlaySoundEffect(SoundEffectSet soundEffect, GameObject caller, out AudioControl audioControl, params ISoundProperty[] soundProperties) | Plays a sound effect set on a pooled temporary emitter or a given Wwise object. The out overloads return an AudioControl to stop or change it. |
void PlaySoundEffect(SoundEffectSet soundEffect, AkGameObj akGameObj, GameObject caller, out AudioControl audioControl, params ISoundProperty[] soundProperties) | Plays a sound effect set on a pooled temporary emitter or a given Wwise object. The out overloads return an AudioControl to stop or change it. |
void PlaySoundEffectAt(SoundEffectSet soundEffect, Vector3 position, GameObject caller, params ISoundProperty[] soundProperties) | Plays a sound effect set at a world position. The same caller can only trigger each sound once per frame. |
void PlaySoundEffectAt(SoundEffectSet soundEffect, Vector3 position, GameObject caller, out AudioControl audioControl, params ISoundProperty[] soundProperties) | Plays a sound effect set at a world position. The same caller can only trigger each sound once per frame. |
void PlaySoundEffectOnObject(SoundEffectSet soundEffect, GameObject targetObject, GameObject caller, params ISoundProperty[] soundProperties) | Plays a sound effect set attached to an object's transform, so it follows the object. |
void PlaySoundEffectOnObject(SoundEffectSet soundEffect, GameObject targetObject, GameObject caller, out AudioControl audioControl, params ISoundProperty[] soundProperties) | Plays a sound effect set attached to an object's transform, so it follows the object. |
SoundEffectSet Resolve(SoundEffectSet effect, SoundEffect fallback, GameObject caller) | Returns the sound effect set, or falls back to the old SoundEffect enum mapping (with a warning) when it is null. |
async void WhenReady(Action callback) | Runs the callback once Wwise has started. Never runs on a headless build. |
protected override void Awake() | On a headless build, suspends sound and disables the component. Otherwise waits for Wwise to start. |
14 private and internal methods
| Member | What it is |
|---|---|
private void DisableSound() | Suspends Wwise and mutes if isSoundDisabledOnServer; when headless also drops the sound map and unloads assets. Runs on server start. |
private void EnableSound() | Wakes Wwise from suspend and unmutes. Runs on client start. |
private PooledTempWwiseAudio GetSoundEventObject(SoundEffectSet set, Vector3 position) | Gets a pooled temporary Wwise object for a sound, optionally placed at a position or attached to a transform. Null if the set has no event. |
private PooledTempWwiseAudio GetSoundEventObject(SoundEffectSet set, Transform transformAttachedTo) | Gets a pooled temporary Wwise object for a sound, optionally placed at a position or attached to a transform. Null if the set has no event. |
private PooledTempWwiseAudio GetSoundEventObject(SoundEffectSet set) | Gets a pooled temporary Wwise object for a sound, optionally placed at a position or attached to a transform. Null if the set has no event. |
private static bool InputDebugStopAudio() | True on the frame S is pressed while Shift and W are held. |
private bool IsAudioValid(SoundEffectSet soundEffect, GameObject caller, out Event soundEvent) | Checks a sound can play: not headless or muted, has a valid event, and not a repeat call this frame. |
private bool IsValidSoundCallThisFrame(SoundEffectSet soundEffect, GameObject caller) | Blocks the same caller from playing the same sound set twice in one frame, when that option is on. |
private AudioControl PlayInternal(SoundEffectSet soundEffect, AkGameObj akGameObj, GameObject caller, ISoundProperty[] soundProperties, bool isControlled, Action endAction = null) | Plays the sound's event on a Wwise object and returns an AudioControl only when a controlled play was asked for. |
private AudioControl PlayInternalOneShot(SoundEffectSet soundEffect, PooledTempWwiseAudio pooledAudio, GameObject caller, ISoundProperty[] soundProperties, bool isControlled) | Registers a pooled temporary Wwise object and plays on it, releasing it back to the pool when the sound ends. |
private void Start() | Subscribes to server and client start to disable or enable sound. |
private static void StopAllWwiseAudio() | Stops all Wwise audio, only in a debug editor build. |
private void Update() | Clears the per-frame caller list and checks the debug stop-audio keys. |
private async Task WaitForLoad() | Waits until Wwise is initialised, then sets the game name. Awaited by WhenReady. |