Sound Design
Sound effects in the game are handled by a single entity named SoundManger
. The SoundManger is a singleton that is responsible for playing sound effects. All created sound effects are stored in a specific folder and named with a specific convention: SFX_<SoundName>, Music_<SoundName>, and Ambient_<SoundName>.
Sound Logic
The in-scene SoundManger is a prefab that will hold a reference to a scriptable object that specifies for each sound effect the name and a set of audio clips.
Each game object that needs to play a sound effect will call the SoundManger to play the sound effect specifying the name of the sound, the priority of execution, and the type. When an execution is demanded, the SoundManager will retrieve the sound effect from the resources by its name and will play it.
If a named sound holds more than one audio clip, the SoundManager will randomly choose one of them and will add a variation to the pitch of the audio clip. This is done to avoid the repetition of the same sound effect.
SFXs are handled with two different pools that differ in the priority of execution. In any case, if any instantiated AudioSource is already playing a sound effect, the new sound effect will be skipped. This is intended to avoid the overlapping of too many sounds.
Music and Ambient sounds are handled differently. These sounds have a dedicated AudioSource for the sake of performance. This is because these sounds are played constantly and they are not supposed to be interrupted by other sounds. If this happens, the sound will be skipped but it’s important to avoid this situation.
Sound Name
The name of the sound to be played is specified in an enum called SoundNames
. This enum contains all the sound effects that are used in the game.