bootstrap website templates

Audio Manager Documentation

Contributors: Jonathan Carter
Documentation Valid for Version: 2.3.3 
Last Updated: 20/06/2020


Contents:

1) Package Contents

The package has five folders:

Editor: AudioManagerEditor.cs
Prefabs: AudioPrefab.prefab
Resourses/Cartergames: Icon.png, Play.png & Stop.png
Scripts: AudioManagerScript.cs & AudioManagerFile.cs
Readme: Text file that links to here

2) First Use Setup

Initial Setup
Once the package has been imported into the project, create a empty gameobject for the manager and add the Audio Manager Script to it or add it to an existing gameobject if you wish. When using the script for the first time it will create a directory "/audio" if it doesn't already exist, you will need to store the audio in this directory for script to work. The script will also create the directory "/audio/files" which is used as the default location for the script to make an audio manager file if it needs to. Next you will need to assign a prefab to the script, this is used to play the audio when you call a function to play a clip. There is a prefab in the package, which is setup correctly, however you are welcome to make your own and customize it.

Directories
As of version 2.3.1, the asset supports multiple directores. If the audio manager file inputted has no directores you will be prompted to add a directory and continue. If there is already a directory you can add additional ones by using the green plus button and remove directories by pressing the red minus button next to the directory you wish to remove.

Scanning & the scanned path
Next you will need to scan the audio clips into the manager, this is done by pressing the scan button. By default the script scans the "/audio" directory, you can change the path to go to a sub-directory within the "/audio" folder by adding a string to the path field in the inspector, if left blank it will return to default.

Example 1: mygame - "/audio/mygame" will be scanned
Example 2: MyGame - "/audio/mygame" will be scanned (capitals are ignored)
Example 3: MyGame/SFX - "/audio/mygame/sfx" will be scanned

The script will also prompt you to press the scan button if you haven't already so that you can use the manager. Once scanned the script will list all the audioclips it has found. This will update on the fly when you add new files into your scanned directory. If there are unscanned items, then you will need to re-scan by pressing the yellow re-scan button (Note: the yellow button only appears once the green scan button has been pressed once).

The Interface
Once it scans the set directory it will show each clip in a list but a preview button and the clip name for each clip. Pressing the preview button (the green arrow) plays the clip associated with it in the inspector, please note that the clip will play at the default volume and pitch. You can stop the preview by pressing the stop button next to the clip, which will appear when a clip is been played (the red square). The names of all the clips can be selected and copied directly from the inspector of the script so you can avoid typo's when calling the sound to be played.

3) Using the Manager to play sounds

The first step to this is getting the manager, referencing the script and assigning it is the easiest way, you can also use findobjectoftype or tags to get the gameobject the script is on and get the audiomanager component. Once you have a reference setup, there are a variety of methods you can use to play the clips.

Play Sound Methods:
All the following functions have the optional passthrough for changing the volume the clip is played at as well as the pitch the clip is played at. You don't have to enter a value into a method call to use them for instance:

AudioManager.PlayClip("MySound") - will play MySound at the default volume of 1 and default pitch of 1.
AudioManager.PlayClip("MySound", .5f) - will play MySound at the volume of 0.5 with the default pitch of 1.


you get the idea.....

PlayClip(string Request, float Volume, float Pitch)
Plays the requested clip as is.

PlayClip(string Request, GameObject Object, float Volume, float Pitch)
Plays the requested clip, but plays it on a different gameobject.

PlayClip(string Request, Vector3 Position, float Volume, float Pitch) 
Plays the requested clip, but plays at the entered location.

PlayFromTime(string Request, float Time, float Volume, float Pitch) 
Plays the requested clip from the desired time.

PlayFromTime(string Request, float Time, GameObject Object, float Volume, float Pitch) 
Plays the requested clip from the desired time, but plays it on a different gameobject.

PlayFromTime(string Request, float Time, Vector3 Position, float Volume, float Pitch) 
Plays the requested clip from the desired time, but plays at the entered location.

PlayWithDelay(string Request, float Delay, float Volume, float Pitch)
Plays the requested clip but waits for the desired time before playing.

PlayWithDelay(string Request, float Delay, GameObject Object, float Volume, float Pitch)
Plays the requested clip but waits for the desired time before playing as well as playing the clip from the desired gameobject.

PlayWithDelay(string Request, float Delay, Vector3 Position, float Volume, float Pitch) 
Plays the requested clip but waits for the desired time before playing as well as playing the clip from the desired location.

PlayRandom(float Volume, float Pitch) 
Plays a random sound from the manager.

PlayRandomFromTime(float Time, float Volume, float Pitch) 
Plays a random sound from the manager but allowing you to add a time to play from if you need it.

PlayRandomWithDelay(float Delay, float Volume, float Pitch) 
Plays a random sound from the manager but allowing you to add delay before playing the chosen clip.

Utility Methods:
These functions are mostly there for utility purposes, say you want to know how many clips the manager has? or want to be able to hot swap the audiomanagerfile the manager uses? these help make this possible.

GetNumberOfClips()
This gets the number of clips stored on the manager it is called from and returns the result. 
Returns: int

GetRandomSound()
This gets a random sound from the manager it is called from and returns the result. 
Returns: AudioClip

ChangeAudioManagerFile(AudioManagerFile File)
This changes the audiomanagerfile used on the audiomanager file in question to the passed through file.

GetAudioManagerFile()
This gets the current audiomanagerfile being used and returns it.
Returns: AudioManagerFile

UpdateLibrary()
Essentially populates the audio manager with the clips currently scanned in the audiomanagerfile in use so they can be used.

4) Error Messages

The scripts have a selection of error messages in the form of console warnings, all errors from this script come with the prefix "(*Audio Manager*):" so you will know it is from this package. Most errors shouldn't come up, but they should explain what you've done wrong and how to fix it.

However, if you run into a problem or get an error and are unsure, feel free to drop me an email at (hello@carter.games) and I'll do my best to help you out.

5) Common Problems

The manager can find my audio:
Please make sure all audio you want to use with this manager is in the /audio directory or in the defined sub-directories you are trying to scan. If this is a feature you require, please do let us know!

I called a function to play audio and nothing happened:
Please make sure you spelt the clip name correctly, note it is CaSe SeNsItIvE, also make sure the code is running with a debug log and the script is references correctly.

I called a function and the clip plays a million times!!!:
This is due to you having the call in an update() or similar, if you have the call in update you need to have either a boolean or a coroutine to stop it been called more than once.

The Inspector hasn't loaded correctly when I added the script:
If this has happened, please sent me screenshots and ways to replicate the problem so I can fix it. email: hello@carter.games

Carter Games Banner Logo (Large)

© Copyright 2019 - 2020 Carter Games - All Rights Reserved