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 a Resources folder in your project.

  • ScriptableObject that maps string keys to AudioClips.

  • Create one AudioRegistry in your Project via Create > MeshMapLabs > Building Blocks > Audio > AudioRegistry. Place it in a Resources folder to be loaded via AudioRegistryCache.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 an AudioSource.

  • Optional pitch randomization.

  • Can trigger on OnEnable or manually.

Example Workflow

  1. Add the AudioManagerWithSettings.prefab to your scene.

  2. Create an AudioRegistry.asset in a Resources folder.

  3. Add unique string keys and AudioClips to the AudioRegistry.

  4. Add three Sliders to your game UI and assign them in AudioSettings.

  5. Add a SliderValueText component to each Slider and assign a TextMeshProUGUI to each.

  6. Play the AudioClips from anywhere in your project by referencing AudioManager.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 and AudioSources preconfigured. Make sure there is an AudioRegistry in your Project.

  • AudioManagerWithSettings — Variant with AudioSettings UI bindings. Requires a UI with volume sliders to be setup.

Last updated