unity-audio
Unity 6 audio system guide. Use when working with sound effects, music, AudioSource, AudioClip, AudioListener, Audio Mixer, spatial audio, or audio optimization. Covers 3D sound, mixer groups, snapshots, and audio import settings. Based on Unity 6.3 LTS documentation.
Nice-Wolf-Studio · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add Nice-Wolf-Studio/unity-claude-skills --skill unity-audio技能说明
name: unity-audio description: > Unity 6 audio system guide. Use when working with sound effects, music, AudioSource, AudioClip, AudioListener, Audio Mixer, spatial audio, or audio optimization. Covers 3D sound, mixer groups, snapshots, and audio import settings. Based on Unity 6.3 LTS documentation.
Unity Audio System
Audio System Overview
Unity's audio system provides full 3D spatial sound, real-time mixing and mastering, hierarchies of mixers, snapshots, and predefined effects. The core architecture follows a source-listener model:
- AudioClip -- A container for audio data imported into the project
- AudioSource -- A component attached to a GameObject that plays AudioClips
- AudioListener -- A microphone-like component (typically on the Main Camera) that receives audio from sources and outputs to speakers
- Audio Mixer -- A central hub for mixing sources, applying effects, and mastering output
Sounds originate from AudioSources attached to objects and are picked up by the AudioListener. Unity calculates a source's distance and position from the listener to determine volume, panning, and 3D effects. The system also models the Doppler Effect using the relative speed of the source and listener objects.
Supported Audio Formats
| Format | Type |
|---|---|
.aif, .wav | Uncompressed |
.mp3, .ogg | Compressed |
.xm, .mod, .it, .s3m | Tracker modules |
Unity supports mono, stereo, and multichannel audio assets (up to eight channels).
AudioSource and AudioListener
AudioSource
The AudioSource component plays an AudioClip in your scene and provides options to customize playback behavior. Key properties:
| Property | Description | Default |
|---|---|---|
clip | The AudioClip to play | None |
volume | Playback volume (0.0 to 1.0) | 1.0 |
pitch | Playback speed/pitch multiplier | 1.0 |
loop | Whether the clip loops on completion | false |
playOnAwake | Auto-play when the GameObject activates | true |
spatialBlend | 2D (0.0) to 3D (1.0) blend | 0.0 |
priority | Source priority (0 = highest, 256 = lowest) | 128 |
mute | Mutes the source without stopping playback | false |
outputAudioMixerGroup | Target mixer group for routing | None |
3D Sound Settings
| Property | Description |
|---|---|
dopplerLevel | Doppler effect intensity scale |
spread | Spread angle in degrees for 3D stereo/multichannel |
rolloffMode | How volume attenuates over distance (Logarithmic, Linear, Custom) |
minDistance | Distance within which volume is at maximum |
maxDistance | Distance beyond which sound is inaudible or stops attenuating |
panStereo | Stereo panning position (-1 left to 1 right) |
reverbZoneMix | Mix level into global reverb |
AudioListener
The AudioListener acts as a microphone-like device that receives input from AudioSources in the scene and outputs through speakers. Critical rules:
- Only one AudioListener per scene -- this is a hard constraint
- Added to the Main Camera by default
- Has no configurable Inspector properties -- it simply must be added to work
- Processes both 3D positional audio and 2D audio (which ignores 3D processing)
- Applies Reverb Zones and Audio Effects to all audible sounds
Static properties available via script:
AudioListener.volume-- Master volume (0.0 to 1.0)AudioListener.pause-- Pauses/unpauses the entire audio system
AudioClip and Import Settings
Load Types
| Load Type | Behavior | Best For |
|---|---|---|
| Decompress On Load | Decompresses immediately on load; uses ~10x memory for Vorbis, ~3.5x for ADPCM | Small, frequently-used sound effects |
| Compressed In Memory | Keeps compressed in memory, decompresses during playback; slight CPU overhead | Medium sounds where decompress-on-load exceeds memory budget |
| Streaming | Decodes on the fly from disk; uses ~200KB buffer per clip | Long audio like music or ambient tracks |
Compression Formats
| Format | Ratio | Best For |
|---|---|---|
| PCM | 1:1 (uncompressed) | Very short effects requiring zero CPU decode cost |
| ADPCM | 3.5:1 | Noise-heavy sounds (footsteps, impacts, weapons) |
| Vorbis/MP3 | Variable (quality slider) | Music and medium-length effects |
Import Settings
| Setting | Description |
|---|---|
| Force To Mono | Mixes multi-channel audio down to a mono track before packing |
| Normalize | Normalizes audio during mono conversion |
| Load In Background | Loads the clip asynchronously to avoid blocking the main thread |
| Ambisonic | Marks the file as containing Ambisonic-encoded soundfields (for XR/360) |
| Preload Audio Data | Preloads clip data when the scene finishes loading (default: enabled) |
| Quality | Compression quality slider for Vorbis/MP3 formats |
| Sample Rate Setting | Preserve, Optimize (auto-adjust), or Override (manual reduction) |
Audio Mixer
The Audio Mixer provides mixing, effects processing, and mastering for audio output. Every Audio Mixer asset contains a Master Group by default.
Core Concepts
- Groups (Buses) -- Signal chains that control volume attenuation and pitch correction; organized hierarchically (e.g.,
Master/SFX/Weapons) - Snapshots -- Saved parameter configurations that can be transitioned between at runtime to create different moods or atmospheres
- Effects -- DSP effects (reverb, echo, EQ, etc.) applied within group signal chains
- Send/Return -- Passes the result from one bus to another for shared effects processing
- Ducking -- Modifies one group's output based on activity in another (e.g., lower ambient when dialogue plays)
- Views -- Different visibility configurations for managing complex mixer layouts
- Exposed Parameters -- Mixer parameters exposed for scrip