The AudioSystem is the Presentation-layer audio module in SaffronLibrary. It plays sound effects and music, manages layered music, applies volume settings to the Unity audio mixer, and resolves audio clips by key with localization support.
Within SaffronLibrary, the system lets other systems request audio without touching Unity audio objects. Callers build audio commands with AudioCommandFactory and send them over the command bus. An AudioFlowController owns the Audio domain and forwards commands and UI events to AudioManager, which carries out the work.
Key responsibilities:
- Command handling:
AudioManagerreceives audio commands and routes them to playback, pause, stop, volume, and layered music operations. - Playback and pooling:
AudioSourcePoolreuses pooledAudioSourceobjects for sound effects and music, andAudioPlaybackUtilityapplies clip settings and fades. - Clip resolution:
AudioClipLookupand theAudioClipHolderfamily map clip keys to clip data, with language fallback for localized clips. - Volume and layered music:
AudioMixerManagersets decibel levels on the mixer, andILayeredMusicPlayeris the contract that layered music backends implement.
Who should use it:
- Gameplay and UI developers who need to play sounds, music, or volume changes. They should use
AudioCommandFactoryrather than constructing commands by hand. - Project developers who subclass
AudioManagerandAudioFlowController, and implementIAudioTweenerandILayeredMusicPlayer, to supply language, volume presets, fading, and a music backend. - Audio content authors who build clip holder assets.
The system depends on the Contracts, Params, Bus, Flow, Initialization, and Application systems for command routing, typed parameters, and bootstrapping. See the architecture page for how these connect.