Audio

The Audio Manager is a singleton component which manages audio playback. The advantages of having this component rather then playing an audio clip directly on an Audio Source are:

  • Allows multiple clips to be played at the same time without one clip stopping another clip from playing.
  • Allows clips to continue playing even if the object is disabled.
  • Allows for easier integration with other assets.

Your workflow doesn’t need to change when you are using the Audio Manager component. If you add an Audio Source to your GameObject the Audio Manager will use the properties from that Audio Source automatically. If a new Audio Source needs to be added to the GameObject it will also use the correct properties.

The Audio Manager works with the following components in order to offer flexibility over how audio is played:

Audio Config

The Audio Config defines how an Audio Clip should be played. The Audio Config allows you to define the settings for that specific audio call. As an example, using the Audio Config you can specify the order that the audio clips are played or which Audio Source should play the audio clip. If an Audio Config is specified the clips from the Audio Config will be used instead of the clips specified within the component inspector. New Audio Config files can be created from the Create -> Opsive -> Audio menu item.

Audio Clips

An array of Audio Clips that can be played.

Clip Selection

Specifies the element that should be selected within the Audio Clips array.

  • Random: A random location within the array.
  • Sequence: Loops from the first to the last array element.
  • Index: Specify the index of the clip to play, defaults to 0. This index can be changed by setting the AudioClipIndex property.
Audio Source Prefab

Prefab which contains the Audio Source that should play the audio.

Share Audio Source

Can the Audio Source be shared between multiple Audio Clips?

Replace Previous Audio Source

Should the Audio Source be replaced by a new Audio Source?

Audio Modifier

Optionally specify the Audio Modifier for the Audio Config.

Audio Modifier

The Audio Modifier allows the playing settings of an Audio Clip to be overridden at runtime. For example, the Audio Modifier can change the Audio Clip’s volume or the pitch. If no override is specified then the default settings on the Audio Source will be used.

Volume Override

Allows the volume to be overridden.

Pitch Override

Allows the pitch to be overridden.

Delay Override

Allows the audio delay to be overridden.

Loop Override

Allows the audio loop to be overridden.

Output Override

Allows the audio output to be overridden.

Audio Clip Set

The Audio Clip Set contains the Audio Config and array of Audio Clips which belong to the set. If an Audio Config is specified then the Audio Clip array will not be used. If the Audio Clip array is used a new clip will be randomly selected out of the list.

Audio Manager Module

The Audio Manager Module is a lightweight object that organizes a group of Audio Sources by the Audio Config and GameObject. The Audio Manager Module can be specified on the Audio Manager and allows for a default Audio Config to be used if no Audio Configs are specified when the audio is played. The Audio Manager Module is also able to redirect the output of the Audio Mixer Group.

API

The AudioManager exists in the Opsive.UltimateCharacterController.Audio namespace and the most common methods that you will use are:

// <summary>
// Plays the clip on the GameObject. The AudioManager will find the next available Audio Source on the specified GameObject.
// </summary>
Play(GameObject gameObject, AudioClip clip)

// <summary>
// Plays the clip on the GameObject with the specified delay. The AudioManager will find the next available Audio Source
// on the specified GameObject.
// </summary>
PlayDelayed(GameObject gameObject, AudioClip clip)

// <summary>
// Stops playing the clip on the Audio Source at the reserved index.
// </summary>
Stop(GameObject gameObject)