PowerQuest
SystemAudio Class Reference

Detailed Description

The PowerQuest Audio System. Provides convenient, 2d specific audio functionality, using audio cues.

Functions are accessable from Quest Scripts using 'Audio.' From other scripts, use the static functions from 'SystemAudio.'

Features:

  • This is an audio cue based system. You create an AudioCue in your project, set up which clips it plays and data like volume, pitch, etc. Then you play that "Cue".
  • Cues can be added to SystemAudio so that you can play them by name. Then it's as simple as calling "Audio.Play("gunshot");
  • Cues have a lot of controls for randomisation so common sounds don't get repetive: set min/max pitch, a list of clips to randomly choose from, and even string multiple cues together with random delays
  • Type based volume control: Flag cues witha type (eg SoundEffect, Music, Dialog), and then set those volumes seperately
  • Basic functions for playing music and ambient loops and crossfading between them
  • Ducking of music when playing dialog
  • Simple 2d falloff and stereo control: Some basic controls set how sounds get quieter, and move left/right based on their position relative to the camera
  • Automatic pooling system for efficiency

Inherits SingletonAuto< SystemAudio >.

Static Public Member Functions

static void SetVolume (AudioCue.eAudioType type, float volume)
 Sets the volume (from 0.0 to 1.0) for audio of a particular type (eg: Sound effects, Music, Dialog) More...
 
static float GetVolume (AudioCue.eAudioType type)
 Retrieves the volume for audio of a particular type (eg: Sound effects, Music, Dialog) More...
 
static AudioCue GetCue (string cueName)
 Retrieves a sound cue by name. More...
 
static AudioHandle Play (string cueName, Transform emmitter=null)
 Play a cue by name. This is the main way to play sounds. If emmitter is set, the sound will falloff/pan as it goes off camera. More...
 
static AudioHandle Play (AudioCue cue, Transform emitter=null, float volumeMult=1, float pitchMult=1, float fromTime=0)
 Play the specified cue with extended options. If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue. More...
 
static AudioHandle Play (AudioCue cue, ref List< AudioHandle > handles, Transform emmitter=null, float volumeMult=1, float pitchMult=1, float fromTime=0)
 Advanced Play function with extended options, and returning a list of all handles started (for when multiple are started). If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue. More...
 
static AudioHandle Play (AudioClip clip, int type=(int) AudioCue.eAudioType.Sound, Transform emmitter=null, float volume=1, float pitch=1, bool loop=false)
 Plays a specific audio clip rather than an audio cue. More...
 
static void Pause (AudioHandle handle)
 Pauses the specified sound by it's handle. More...
 
static void UnPause (AudioHandle handle)
 Resumes the specified sound by it's handle. More...
 
static void Stop (AudioHandle handle, float overTime=0)
 Stops the specified sound by it's handle. More...
 
static AudioHandle PlayMusic (string name, float fadeTime=0)
 Play a music track using the cue name, with optional crossfade time. More...
 
static AudioHandle PlayMusic (string name, float fadeOutTime, float fadeInTime)
 Play a music track using the cue name, with seperate fade out and fade in times. More...
 
static AudioHandle PlayMusic (AudioCue cue, float fadeTime=0)
 Play a music cue, with optional crossfade time. More...
 
static AudioHandle PlayMusic (AudioCue cue, float fadeOutTime, float fadeInTime)
 Play a music cue, with seperate fade out and fade in times. More...
 
static AudioSource PlayMusicSynced (string name, float fadeTime, float volumeOverride=0)
 Play a music track using the cue name, Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier. More...
 
static AudioSource PlayMusicSynced (AudioCue cue, float fadeTime, float volumeOverride=0)
 Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier. More...
 
static void StopMusic (float fadeTime=0)
 Stops the currently playing music, with optional fade out time. More...
 
static void PlayAmbientSound (string name, float fadeTime=0.4f)
 Plays an ambient sound by it's cue name, with optional fade time. Sound cue is assumed to be looping, and will be automatically restarted on save/reload. More...
 
static void StopAmbientSound (float overTime=0.4f)
 Plays an ambient sound cue, with optional fade time. Sound cue is assumed to be looping, and will be automatically restarted on save/reload. More...
 

Public Member Functions

float GetVolume (AudioHandle source)
 Gets the base volume of a particular sound effect (usually use the AudioHandle for this) More...
 
void SetVolume (AudioHandle source, float volume)
 Sets the base volume of a particular sound effect (usually use the AudioHandle for this) More...
 
float GetCueVolume (AudioCue cue, AudioClip specificClip=null)
 Advanced function to retrieve a cue's default volume. More...
 
void PauseAllSounds ()
 Advanced function that pauses all sounds (used when pausing game) More...
 
void ResumeAllSounds ()
 Advanced function that resumes all paused sounds (used when pausing game) More...
 
AudioHandle GetActiveMusicHandle ()
 Advanced function for retrieving the active music handle. More...
 
bool GetIsActiveMusic (AudioCue cue)
 Advanced function returns true if the passed cue is the active music. More...
 
bool AddCue (AudioCue cue)
 Editor function for adding an audio cue to the list of cues playable by name. Primarily used by editor. Returns true if added, false if it already existed. More...
 
List< AudioCue > GetAudioCues ()
 Editor function for retrieving all audio cues. More...
 
object GetSaveData ()
 Internal function. More...
 
void RestoreSaveData (object obj)
 Internal function. More...
 

Member Function Documentation

◆ SetVolume() [1/2]

static void SetVolume ( AudioCue.eAudioType  type,
float  volume 
)
inlinestatic

Sets the volume (from 0.0 to 1.0) for audio of a particular type (eg: Sound effects, Music, Dialog)

◆ GetVolume() [1/2]

static float GetVolume ( AudioCue.eAudioType  type)
inlinestatic

Retrieves the volume for audio of a particular type (eg: Sound effects, Music, Dialog)

◆ GetVolume() [2/2]

float GetVolume ( AudioHandle  source)
inline

Gets the base volume of a particular sound effect (usually use the AudioHandle for this)

◆ SetVolume() [2/2]

void SetVolume ( AudioHandle  source,
float  volume 
)
inline

Sets the base volume of a particular sound effect (usually use the AudioHandle for this)

◆ GetCue()

static AudioCue GetCue ( string  cueName)
inlinestatic

Retrieves a sound cue by name.

◆ Play() [1/4]

static AudioHandle Play ( string  cueName,
Transform  emmitter = null 
)
inlinestatic

Play a cue by name. This is the main way to play sounds. If emmitter is set, the sound will falloff/pan as it goes off camera.

Eg: Audio.Play("Gunshot", C.Gunman.Instance);

◆ Play() [2/4]

static AudioHandle Play ( AudioCue  cue,
Transform  emitter = null,
float  volumeMult = 1,
float  pitchMult = 1,
float  fromTime = 0 
)
inlinestatic

Play the specified cue with extended options. If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue.

◆ Play() [3/4]

static AudioHandle Play ( AudioCue  cue,
ref List< AudioHandle handles,
Transform  emmitter = null,
float  volumeMult = 1,
float  pitchMult = 1,
float  fromTime = 0 
)
inlinestatic

Advanced Play function with extended options, and returning a list of all handles started (for when multiple are started). If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue.

◆ Play() [4/4]

static AudioHandle Play ( AudioClip  clip,
int  type = (int)AudioCue.eAudioType.Sound,
Transform  emmitter = null,
float  volume = 1,
float  pitch = 1,
bool  loop = false 
)
inlinestatic

Plays a specific audio clip rather than an audio cue.

◆ Pause()

static void Pause ( AudioHandle  handle)
inlinestatic

Pauses the specified sound by it's handle.

◆ UnPause()

static void UnPause ( AudioHandle  handle)
inlinestatic

Resumes the specified sound by it's handle.

◆ Stop()

static void Stop ( AudioHandle  handle,
float  overTime = 0 
)
inlinestatic

Stops the specified sound by it's handle.

◆ PlayMusic() [1/4]

static AudioHandle PlayMusic ( string  name,
float  fadeTime = 0 
)
inlinestatic

Play a music track using the cue name, with optional crossfade time.

◆ PlayMusic() [2/4]

static AudioHandle PlayMusic ( string  name,
float  fadeOutTime,
float  fadeInTime 
)
inlinestatic

Play a music track using the cue name, with seperate fade out and fade in times.

◆ PlayMusic() [3/4]

static AudioHandle PlayMusic ( AudioCue  cue,
float  fadeTime = 0 
)
inlinestatic

Play a music cue, with optional crossfade time.

◆ PlayMusic() [4/4]

static AudioHandle PlayMusic ( AudioCue  cue,
float  fadeOutTime,
float  fadeInTime 
)
inlinestatic

Play a music cue, with seperate fade out and fade in times.

◆ PlayMusicSynced() [1/2]

static AudioSource PlayMusicSynced ( string  name,
float  fadeTime,
float  volumeOverride = 0 
)
inlinestatic

Play a music track using the cue name, Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier.

◆ PlayMusicSynced() [2/2]

static AudioSource PlayMusicSynced ( AudioCue  cue,
float  fadeTime,
float  volumeOverride = 0 
)
inlinestatic

Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier.

◆ StopMusic()

static void StopMusic ( float  fadeTime = 0)
inlinestatic

Stops the currently playing music, with optional fade out time.

◆ PlayAmbientSound()

static void PlayAmbientSound ( string  name,
float  fadeTime = 0.4f 
)
inlinestatic

Plays an ambient sound by it's cue name, with optional fade time. Sound cue is assumed to be looping, and will be automatically restarted on save/reload.

◆ StopAmbientSound()

static void StopAmbientSound ( float  overTime = 0.4f)
inlinestatic

Plays an ambient sound cue, with optional fade time. Sound cue is assumed to be looping, and will be automatically restarted on save/reload.

◆ GetCueVolume()

float GetCueVolume ( AudioCue  cue,
AudioClip  specificClip = null 
)
inline

Advanced function to retrieve a cue's default volume.

◆ PauseAllSounds()

void PauseAllSounds ( )
inline

Advanced function that pauses all sounds (used when pausing game)

◆ ResumeAllSounds()

void ResumeAllSounds ( )
inline

Advanced function that resumes all paused sounds (used when pausing game)

◆ GetActiveMusicHandle()

AudioHandle GetActiveMusicHandle ( )
inline

Advanced function for retrieving the active music handle.

◆ GetIsActiveMusic()

bool GetIsActiveMusic ( AudioCue  cue)
inline

Advanced function returns true if the passed cue is the active music.

◆ AddCue()

bool AddCue ( AudioCue  cue)
inline

Editor function for adding an audio cue to the list of cues playable by name. Primarily used by editor. Returns true if added, false if it already existed.

◆ GetAudioCues()

List<AudioCue> GetAudioCues ( )
inline

Editor function for retrieving all audio cues.

◆ GetSaveData()

object GetSaveData ( )
inline

Internal function.

◆ RestoreSaveData()

void RestoreSaveData ( object  obj)
inline

Internal function.