🗺️ AudioManager

AudioManager – Component Overview

The AudioManager is a centralized system for playing, looping, and managing audio in the Virtual Pet Game Template. It allows tag-based volume control, simultaneous SFX playback, ambient loops, and dynamic volume adjustments through settings UI.


🎵 What It Does

  • Handles one-shot sound effects with concurrency limit

  • Supports looping sounds by tag (e.g., rain, shower)

  • Plays ambient and loading background music independently

  • Allows custom tag volume control for specific gameplay needs

  • Saves and loads volume preferences via PlayerPrefs


🔧 Inspector Configuration

  • Audio Sources:

    • masterAudioSource: main SFX source

    • ambientAudioSource: looped ambience

    • loadingAudioSource: loading screen music

  • Volume Settings:

    • masterVolume, vfxVolume, ambienceVolume

    • customTagVolumes: per-tag volume definitions

  • Limitations:

    • maxConcurrentAudio: limits how many SFX can play at once


🧠 How It Works

Initialization

  • Loads volume preferences from PlayerPrefs

  • Sets initial volume on audio sources

  • Ensures ambientAudioSource loops

One-Shot Audio

  • Plays an SFX using the master audio source

  • Checks for concurrency limit

  • Uses per-tag volume control

Looping Audio

  • Starts a looping sound for a tag (adds AudioSource if missing)

  • Stops and removes looping source for a tag

Ambient & Loading

  • PlayAmbientAudio(clip) plays persistent ambiance

  • PlayLoadingMenu(clip) plays loading screen music

Volume Control (Settings Menu)

  • Updates built-in volume and saves to PlayerPrefs

  • Adds/updates volume for custom tags


🔍 Integration Examples

  • Play a sound effect:

  • Play ambient track:

  • Loop sound by tag:

  • Update VFX slider:


✅ Highlights

  • 🎧 Centralized one-shot and looping playback

  • ⚖️ Per-tag volume and concurrency cap

  • ☁️ Ambient / loading music separation

  • ↺ Dynamic control for UI settings

A robust and modular audio solution tailored for casual mobile games, pet simulators, and minigame-driven environments.

Last updated