Skip to content

Audio Helpers

Optional helper components for common audio scenarios. These are convenience utilities that wrap the Core AudioService - not part of the Core framework itself.

SimpleAudioPlayer

A drop-in component for basic audio playback needs.

Use Cases

  • Background music for scenes
  • Ambient sounds (rain, wind, crowd noise)
  • Simple sound effects triggered by game events
  • Any scenario where you need straightforward audio playback

Features

  • Clean ServiceLocator integration with lazy resolution
  • Configurable fade-in/fade-out
  • Volume and loop controls
  • Optional track assignment
  • Play on Start / Stop on Disable options
  • No hardcoded assumptions about your game
  • Thread-safe service resolution
  • Comprehensive error handling

Quick Setup

  1. Add SimpleAudioPlayer component to any GameObject
  2. Set the audioId to your asset identifier (e.g., "Audio/Music/MenuTheme")
  3. Configure volume, loop, fade settings as needed
  4. Optionally set playOnStart to true for automatic playback

Code Examples

Basic Usage:

// Get reference and control playback
var audioPlayer = GetComponent<SimpleAudioPlayer>();
audioPlayer.SetAudioId("Audio/Music/LevelTheme", true); // Play immediately
audioPlayer.Stop(); // Stop with fade-out

Dynamic Audio Switching:

// Switch between different audio based on game state
if (inCombat)
    audioPlayer.SetAudioId("Audio/Music/Combat", true);
else
    audioPlayer.SetAudioId("Audio/Music/Exploration", true);

Check Playback Status:

if (audioPlayer.IsPlaying)
    Debug.Log($"Currently playing: {audioPlayer.CurrentAudioId}");

Configuration Options

Field Description Default
audioId Asset identifier for the resource system ""
volume Playback volume (0.0 to 1.0) 1.0
loop Loop the audio continuously false
fadeInDuration Fade-in duration in seconds 0
fadeOutDuration Fade-out duration in seconds 0
trackName Audio mixer track (leave empty for default) ""
playOnStart Auto-play when component starts false
stopOnDisable Auto-stop when component is disabled false

Framework Philosophy

This helper follows LoL Engine principles:

  • Optional: Use it or replace it with your own logic
  • No Core dependencies: Doesn't modify Core behavior
  • Clean abstraction: Proper ServiceLocator usage
  • Zero assumptions: No hardcoded game-specific values
  • Extensible: Easy to subclass or modify for specific needs

When Not to Use

  • Complex audio management requiring custom logic
  • Performance-critical scenarios needing direct AudioService access
  • Advanced audio features not exposed by this simple wrapper
  • When you need tight integration with custom audio systems

For those cases, use the Core AudioService directly through ServiceLocator, or see Audio.md for AdvancedAudioPlayer, AudioPreloadManager, and the AAA Audio Orchestrator.

Error Handling

The component provides clear warnings for common issues: - Missing AudioService (initialization problems) - Empty audio IDs (configuration issues) - Invalid track names (mixer configuration problems) - Asset loading failures (resource system issues)

All warnings include the GameObject name and component context for easy debugging.