Audio
The Audio system provides a centralized way to manage music, sound effects (SFX), and UI sounds.
Components
Singleton manager for playing music, SFX, and UI
AudioClips
.Supports:
Mixer group routing (
MusicGroup
,SFXGroup
,UIGroup
).Fade-in/out for music.
Saving/restoring music playback positions.
Randomized pitch for SFX/UI.
Requires an
AudioRegistry
.asset in aResources
folder in your project.
ScriptableObject
that mapsstring
keys toAudioClips
.Create one
AudioRegistry
in your Project viaCreate > MeshMapLabs > Building Blocks > Audio > AudioRegistry
. Place it in aResources
folder to be loaded viaAudioRegistryCache.Instance
.Change load path dynamically with
AudioRegistryCache.SetResourcePath()
.
UI slider bindings for mixer volume control.
Saves user preferences to
PlayerPrefs
.Mixer parameters:
MusicVolume
,SFXVolume
,UIVolume
.
Simple
MonoBehaviour
to play a clip on anAudioSource
.Optional pitch randomization.
Can trigger on
OnEnable
or manually.
Example Workflow
Add the
AudioManagerWithSettings
.prefab to your scene.Create an
AudioRegistry
.asset in aResources
folder.Add unique
string
keys andAudioClips
to theAudioRegistry
.Add three
Sliders
to your game UI and assign them inAudioSettings
.Add a
SliderValueText
component to eachSlider
and assign aTextMeshProUGUI
to each.Play the
AudioClips
from anywhere in your project by referencingAudioManager.Instance
.
Example Code
// Play UI sound
AudioManager.Instance.PlayUI("UI.ButtonClick", randomizePitch: true);
// Play looping background music
AudioManager.Instance.PlayMusic("Music.MainTheme", loop: true, fadeIn: true);
// Adjust music volume via UI slider
public void OnMusicVolumeChanged(float value)
{
AudioManager.Instance.SetMusicVolume(value);
}
Prefabs
AudioManager — Ready-to-use manager
GameObject
with mixer groups andAudioSource
s preconfigured. Make sure there is anAudioRegistry
in your Project.AudioManagerWithSettings — Variant with
AudioSettings
UI bindings. Requires a UI with volume sliders to be setup.
Last updated