Click or drag to resize

AudioController Class

The audio managing class used to define and play audio items and categories.
Inheritance Hierarchy
SystemObject
  Object
    Component
      Behaviour
        MonoBehaviour
          (Default Namespace)SingletonMonoBehaviourAudioController
            (Default Namespace)AudioController

Namespace:  (Default Namespace)
Assembly:  AudioToolkit (in AudioToolkit.dll) Version: 8.2.0.0 (8.2.0.0)
Syntax
C#
public class AudioController : SingletonMonoBehaviour<AudioController>, 
	ISerializationCallbackReceiver

The AudioController type exposes the following members.

Constructors
  NameDescription
Public methodAudioController
Initializes a new instance of the AudioController class
Top
Properties
  NameDescription
Public propertyambienceSoundCrossFadeTime_In
Specifies a specific fade-in time for ambience sound cross fading. Only meaningful if specifyCrossFadeInAndOutSeperately is enabled.
Public propertyambienceSoundCrossFadeTime_Out
Specifies a specific fade-out time for ambience sound cross fading. Only meaningful if specifyCrossFadeInAndOutSeperately is enabled.
Public propertyambienceSoundEnabled
Gets or sets the ambienceSoundEnabled.
Public propertyDisableAudio
Disables all audio playback.
Public propertyisAdditionalAudioController
You may use several AudioControllers in the same scene in parallel. All but one (the main controller) must be marked as 'additional'. You can play audio items of any of those controllers with the normal Play() calls.
Public propertyisSingletonObject
returns true if the AudioController is the main controller (not an additional controller)
(Overrides SingletonMonoBehaviourTisSingletonObject.)
Public propertymusicCrossFadeTime_In
Specifies a specific fade-in time for music cross fading. Only meaningful if specifyCrossFadeInAndOutSeperately is enabled.
Public propertymusicCrossFadeTime_Out
Specifies a specific fade-out time for music cross fading. Only meaningful if specifyCrossFadeInAndOutSeperately is enabled.
Public propertymusicEnabled
Gets or sets the musicEnabled.
Public propertysoundMuted
Gets or sets the soundMuted.
Public propertyStatic membersystemDeltaTime
Returns the high precision audio system delta time since the last frame update.
Public propertyStatic membersystemTime
Returns the high precision audio system time size the application launch.
Public propertyVolume
The global volume applied to all categories. You change the volume by script and the change will be apply to all playing audios immediately.
Top
Methods
  NameDescription
Public methodStatic memberAddPlaylist
Adds a new playlist.
Public methodStatic memberCode exampleAddToCategory(AudioCategory, AudioItem)
Adds a custom audio item to a category.
Public methodStatic memberAddToCategory(AudioCategory, AudioClip, String)
Creates an AudioItem with the name audioID containing a single subitem playing the specified custom AudioClip. This AudioItem is then added to the specified category.
Public methodStatic memberClearPlaylists
Clears all music playlist.
Public methodStatic memberDetachAllAudios
Detaches all audio objects possibly parented to the specified game object.
Public methodStatic memberEnableAmbienceSound
Enables the ambience sound.
Public methodStatic memberEnableMusic
Enables the music.
Public methodStatic memberEnqueueMusic
Enqueues an audio ID to the music playlist queue.
Public methodStatic memberFadeInCategory
Starts a fade-in of an audio category.
Public methodStatic memberFadeOutCategory
Starts a fade-out of an audio category.
Public methodStatic memberGetAudioItem
Returns the AudioItem with the given audioID.
Public methodStatic memberGetAudioItemMaxDistance
Gets the audio item's max distance. (respects all proper default values and overwrites).
Public methodStatic memberGetCategory
Gets a category.
Public methodStatic memberGetCategoryVolume
Gets the category volume.
Public methodStatic memberGetCurrentAmbienceSound
Gets the current ambience sound.
Public methodStatic memberGetCurrentAudioListener
Gets the currently active Unity audio listener.
Public methodStatic memberGetCurrentMusic
Gets the current music.
Public methodStatic memberGetGlobalVolume
Gets the global volume.
Public methodStatic memberGetMusicPlaylist
If playlistName == null then gets a copy of the current playlist audioID array, otherwise gets a copy of the playlist with the specified name
Public methodStatic memberGetPlayingAudioObjects(Boolean)
Returns an array of all playing audio objects.
Public methodStatic memberGetPlayingAudioObjects(String, Boolean)
Returns an array of all playing audio objects with the specified audioID.
Public methodStatic memberGetPlayingAudioObjectsCount
Returns the number of all playing audio objects with the specified audioID.
Public methodStatic memberGetPlayingAudioObjectsInCategory
Returns an array of all playing audio objects in the category with name categoryName.
Public methodGetPlaylistByName
Retrieves a playlist by name. If playlists are named identically it will return the first one it finds
Public methodInitializeAudioItems
Updates the internal audioID dictionary and initializes all registered AudioItem objects.
Public methodStatic memberIsAmbienceSoundEnabled
Determines whether ambience sound is enabled.
Public methodStatic memberIsAmbienceSoundPaused
Uses to test if ambience sound is paused
Public methodStatic memberIsMusicEnabled
Determines whether music is enabled.
Public methodStatic memberIsMusicPaused
Uses to test if music is paused
Public methodStatic memberIsPlaying
Determines whether the specified audio ID is playing.
Public methodStatic memberIsPlaylistPlaying
Determines whether the playlist is playing.
Public methodStatic memberIsSoundMuted
Determines whether sound is muted
Public methodStatic memberIsValidAudioID
Tests if a given audioID is valid.
Public methodStatic memberMuteSound
Mutes / Unmutes the sound.
Public methodStatic memberNewCategory
Creates a new audio category
Public methodOnAfterDeserialize
Public methodOnBeforeSerialize
Public methodStatic memberPauseAll
Pauses all playing audio items (including the music).
Public methodStatic memberPauseAmbienceSound
Pauses the currently playing ambience sound.
Public methodStatic memberPauseCategory
Pauses all playing audio items in the specified category (including the music).
Public methodStatic memberPauseMusic
Pauses the currently playing music.
Public methodStatic memberPlay(String)
Plays an audio item with the name audioID.
Public methodStatic memberPlay(String, Transform)
Plays an audio item with the name audioID parented to a specified transform.
Public methodStatic memberPlay(String, Vector3, Transform)
Plays an audio item with the name audioID parented to a specified transform with a world offset.
Public methodStatic memberPlay(String, Single, Single, Single)
Plays an audio item with the name audioID.
Public methodStatic memberPlay(String, Transform, Single, Single, Single)
Plays an audio item with the name audioID parented to a specified transform.
Public methodStatic memberPlay(String, Vector3, Transform, Single, Single, Single)
Plays an audio item with the name audioID parented to a specified transform with a world offset.
Public methodStatic memberPlayAfter
Plays an audio item with the name audioID right after the given AudioObject stops playing. (see the Unity AudioSettings.dspTime documentation)
Public methodStatic memberPlayAmbienceSound(String, Single, Single, Single)
Plays an audio item with the name audioID as ambience sound.
Public methodStatic memberPlayAmbienceSound(String, Transform, Single, Single, Single)
Plays an audio item with the name audioID as ambience sound at the specified position.
Public methodStatic memberPlayAmbienceSound(String, Vector3, Transform, Single, Single, Single)
Plays an audio item with the name audioID as ambience sound at the specified position.
Public methodPlayAudioItem
Plays a specific AudioItem.
Public methodPlayAudioSubItem
Plays a specific AudioSubItem.
Public methodStatic memberPlayMusic(String, Single, Single, Single)
Plays an audio item with the name audioID as music.
Public methodStatic memberPlayMusic(String, Transform, Single, Single, Single)
Plays an audio item with the name audioID as music at the specified position.
Public methodStatic memberPlayMusic(String, Vector3, Transform, Single, Single, Single)
Plays an audio item with the name audioID as music at the specified position.
Public methodStatic memberPlayMusicPlaylist
Start playing the music playlist.
Public methodStatic memberPlayNextMusicOnPlaylist
Jumps to the next the music track on the playlist.
Public methodStatic memberPlayPreviousMusicOnPlaylist
Jumps to the previous music track on the playlist.
Public methodStatic memberPlayScheduled
Plays an audio item with the name audioID parented to a specified transform with a world offset scheduled at a specified high precision DSP time (see the Unity AudioSettings.dspTime documentation)
Public methodStatic memberRemoveAudioItem
Removes an AudioItem from the AudioController.
Public methodStatic memberRemoveCategory
Removes an audio category.
Public methodStatic memberSetCategoryVolume
Changes the category volume. Also effects currently playing audio items.
Public methodStatic memberSetCurrentMusicPlaylist
Sets the current playlist to the specified audioID array
Public methodStatic memberSetGlobalVolume
Changes the global volume. Effects all currently playing audio items.
Public methodStatic memberStop(String)
Stops all playing audio items with name audioID.
Public methodStatic memberStop(String, Single)
Stops all playing audio items with name audioID with a fade-out.
Public methodStatic memberStopAll
Immediately stops playing audio items (including the music).
Public methodStatic memberStopAll(Single)
Fades out all playing audio items (including the music).
Public methodStatic memberStopAmbienceSound
Stops the currently playing ambience sound.
Public methodStatic memberStopAmbienceSound(Single)
Stops the currently playing ambience sound with fade-out.
Public methodStatic memberStopCategory
Stops all playing audio items in the specified category (including the music).
Public methodStatic memberStopMusic
Stops the currently playing music.
Public methodStatic memberStopMusic(Single)
Stops the currently playing music with fade-out.
Public methodUnloadAllAudioClips
Unloads all AudioClips specified in this AudioController from memory.
Public methodStatic memberUnpauseAll
Un-pauses all playing audio items (including the music).
Public methodStatic memberUnpauseAmbienceSound
Unpauses the current ambience sound.
Public methodStatic memberUnpauseCategory
Un-pauses all playing audio items in the specified category (including the music).
Public methodStatic memberUnpauseMusic
Unpauses the current music.
Top
Fields
  NameDescription
Public field_currentInspectorSelection
Public fieldambienceSoundCrossFadeTime
If set to a value > 0 (in seconds) music will automatically be cross-faded with this fading time.
Public fieldStatic memberAUDIO_TOOLKIT_VERSION
A string containing the version number of the Audio Toolkit
Public fieldAudioCategories
Specify your audio categories here using the Unity inspector.
Public fieldAudioObjectPrefab
You must specify your AudioObject prefab here using the Unity inspector.
  • AudioObjectAudioSource (Unity built-in)PoolableObject - only required if pooling is uses
Public fieldcrossfadePlaylist
if enabled, the tracks on the playlist will get cross-faded as specified by musicCrossFadeTime
Public fielddelayBetweenPlaylistTracks
Mute time in between two tracks on the playlist.
Public fieldEqualPowerCrossfade
If enabled fading is adjusted in a way so that cross-fades should result in the same power during the time of fadeing
Public fieldloopPlaylist
specifies if the music playlist will get looped
Public fieldmusicCrossFadeTime
If set to a value > 0 (in seconds) music will automatically be cross-faded with this fading time.
Public fieldmusicPlaylist Obsolete.
For backwards compatibility we still keep the old playlist system, its items will be copied over to the Default Playlist and then cleared
Public fieldmusicPlaylists
allows to specify a list of named playlist that can be played as music
Public fieldPersistent
If enabled, the audio controller will survive scene changes
Public fieldPlayWithZeroVolume
If disabled, audios are not played if they have a resulting volume of zero.
Public fieldshufflePlaylist
enables / disables shuffling for the music playlist
Public fieldspecifyCrossFadeInAndOutSeperately
If enabled specific music and ambience sound cross-fading in and out times can be specified with musicCrossFadeTime_In and musicCrossFadeTime_Out respectively ambienceSoundCrossFadeTime_In and ambienceSoundCrossFadeTime_Out
Public fieldUnloadAudioClipsOnDestroy
If enabled all audio resources (AudioClips) specified in this AudioController are unloaded from memory when the AudioController gets destroyed (e.g. when loading a new scene and Persistent is not enabled)
Public fieldUsePooledAudioObjects
Enables / Disables AudioObject pooling
Top
Remarks
At least one instance of an AudioController must exist in each scene using the Audio Toolkit. Usually there is exactly one controller, but you can have additional controllers if they are marked as such (in the Unity insepector, see isAdditionalAudioController) There a two options when setting up an AudioController. Either you can specify all audio files that are used in your entire project in one single AudioController. Then add this AudioController to your initial scene and set it persistent from within the inspector, so it will survive when a new scene is loaded. This way all audios are accessible from within your entire application. If you have a lot of audio files though, this may lead to a lengthy loading time and will have a rather large memory footprint. To avoid this, you can alternatively set up a specific AudioController for each scene which only contains those audio files needed in the particular scene.
Examples
Once you have defined your audio categories and items in the Unity inspector you can play music and sound effects very easily:
AudioController.Play( "MySoundEffect1" );
AudioController.Play( "MySoundEffect2", new Vector3( posX, posY, posZ ) );
AudioController.PlayMusic( "MusicTrack1" );
AudioController.SetCategoryVolume( "Music", 0.5f );
AudioController.PauseMusic();
See Also