Simple Audio Manager

User Manual

  1. Overview
  2. Quick Start
  3. Play audio options
  4. Audio groups (MUSIC, SFX , VOICE, GLOBAL)
  5. Limit the amount of simultaneously playing sounds
  6. Audio queues
  7. Examples
  8. API reference

 

1. Overview

Simple Audio Manager is a lightweight and convenient Unity3D class liblary and editor extention for manipulating a various sounds playback in the game.

  • Simply play sounds with various options;
  • Use predefined audio groups (GLOBAL, SFX, MUSIC, VOICE) or create custom audio groups to simply manipulate their properties;
  • Limit a number of simultaneously playing sounds to increase productivity;
  • Set priorities for sounds while using limits;
  • Create audio queues to play sounds continuously;
  • Expandable at your discretion.

2. Quick start (for C#)

a) Locate 'SimpleAudioManager' prefab at the 'SimpleAudioManager/Prefabs' folder, then drag it onto the Scene.

b) Use the following editor form to manipulate a properties of 'SimpleAudioManager':

c) Copy the following code into your Script:

private AudioStreamSystem _sound;
public AudioStreamSystem sound
{
    get
    {
        if (_sound == null)
            _sound =   GameObject.Find("SimpleAudioManager").GetComponent<AudioStreamSystem>();
        return _sound;
    }
}

d) Use the following code to play sounds (at the same script as you used above):

sound.Play(yourSound); //yourSound means instance of AudioClip class

or

Track track = sound.CreateTrack();
track.clip = youSound;
track.Play();

Check out a Demo and API Reference

3. Play audio options

Enumeration

public enum AudioOption : uint

contains the following options:

LOOP

Sound plays looping.

REPLAY

Sound will play again from the beginning when recalling Play(track).

ONLY_ONE

Sound will not play if another sound with option ONLY_ONE is currently active.

OVERRIDE

Replaces by itself another sound with ONLY_ONE option.

FOLLOW

Sound follows Transform target (actual for 3D sounds);

FOLLOW_STOP

Sound will stop if Transform target gets hidden or destroyed.

LIMIT

Sound will not play if the limit of simultaneously playing sounds has exceeded (the only sounds with option LIMIT are considered for that limit)

PRIORITY

When the limit is exceeded replaces by itself another sound with LIMIT, but without PRIORITY option.

IGNORE_NULL

Exceptions if clip == null will be ignored.

sound.Play((AudioClip) null, AudioOption.IGNORE_NULL);

Same as:

ac = null;
if (ac != null)
    sound.Play(ac)

PREVENT_STOP 

Prevents sound to be stopped.

When active = false, sound sets paused instead of stop.

sound[AudioOption.SFX].active = false;
sound.Play(sound1, AudioOption.SFX | AudioOption.PREVENT_STOP);
sound.Play(sound2, AudioOption.SFX);
sound[AudioOption.SFX].active = true;

sound1 will continue playing from paused position, while sound2 will play from the beginning.

4. Audio groups (MUSIC, SFX , VOICE, GLOBAL)

Use the following predefined audio groups to manipulate the volume and ativity of multiple sounds in the game:

GLOBAL

Predefined group for all existing sounds. Changing it's properties infuences all other groups as well.

MUSIC

Predefined group for background music.

SFX

Predefined group for sound effects.

VOICE

Predefined group for voice overs.

Properties of groups:

active

Boolean. When active=true, group can play sounds. Otherwise group is muted.

volume

Number from 0 to 1.

Examples:

a) Change propeties of group:

public class AudioGroupDetail

AudioGroupDetail group = sound[AudioOption.SFX];
group.active = false;
          
sound.GetLocal(AudioOption.SFX).volume = 1.0f;

b) Play sound in MUSIC group:

sound.Play(youSound, AudioOption.MUSIC);

c) Reduce MUSIC group volume by 50%:

sound[AudioOption.MUSIC].volume = 0.5f;

d) Reduce all sounds volume d by 50%:

sound[AudioOption.GLOBAL].volume = 0.5f;

5. Limit the amount of simultaneously playing sounds

To to increase productivity set a reasonable limit of simultaneously playing sounds.

Audio queues

Use TrackStream class to play a multiple sounds continuously.

public class TrackStream

Example:

//Play queue
var trackStream = sound.CreateTrackStream();
trackStream.Add(testSound1, AudioOption.SFX);
trackStream.Add(testSound2, AudioOption.SFX);
trackStream.Play();

TrackSream starts the next sound in the queue after the previous sound finishes.

globalOption

Options of all tracks of TrackStream class

option

Options of single TrackSream

trackStream.globalOption |= AudioOption.SFX;
trackStream.option = AudioOption.LOOP;

6. Examples

Examples can be found inside the Simple Audio Manager package at ExampleAudio scene.

Check out a Demo and API Reference as well.

 


© Copyright 2011 – 2013 Black Fox Studio LLC. All rights reserved.