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.
Audio Clip Set
The Audio Clip Set makes it easy to randomly play a clip out of a set of multiple audio clips:
New clips can be added by selecting the plus button on the bottom right. Once a row is selected it can be removed by selecting the minus button.
When a clip needs to be played the clip will be randomly selected out of this list. A delay can be specified which will prevent the audio from playing for the specified number of seconds.
The AudioManager exists in the Opsive.UltimateCharacterController.Audio namespace and the most common methods that you will use are:
// <summary> // Registers the AudioSources on the GameObject so they can be played. The Register method should be called before any clip // is played. // </summary> Register(GameObject gameObject) // <summary> // In some cases you may want the AudioManager to always play on the same Audio Source and don’t want any other clips to play // on that Audio Source. Setting the reserve count will reserve the number of Audio Sources so they can only be played when // explicitly called. The reserve index is used by the Equip/Unequip clips for the items because both equip and unequip will // never need to play at the same time. // </summary> SetReserveCount(GameObject gameObject, int count) // <summary> // Plays the clip on the GameObject. The AudioManager will find the next available Audio Source on the specified GameObject. // An optional reserved index can be specified if the clip should play on a specific Audio Source. // </summary> Play(GameObject gameObject, AudioClip clip, int reservedIndex (optional)) // <summary> // Plays the clip on the GameObject with the specified delay. The AudioManager will find the next available Audio Source // on the specified GameObject. An optional reserved index can be specified if the clip should play on a specific Audio Source. // </summary> PlayDelayed(GameObject gameObject, AudioClip clip, int reservedIndex (optional)) // <summary> // Stops playing the clip on the Audio Source at the reserved index. // </summary> Stop(GameObject gameObject, int reservedIndex)