Ignition / AudioChannels

Namespace Playniax.Ignition.Framework

Inherits from MonoBehaviour

Class or component can be found in Assets/Playniax/Ignition/Framework/Scripts (MonoBehaviour)/AudioChannels.cs

Public fieldsDescription
static bool mute = falseGlobal variable to enable or disable sound.
static AudioSource[] channelsAllocated channels.

Public MethodsDescription
static AudioSource GetAvailableChannel()Returns the first available channel.
static AudioSource Play(AudioClip audioClip, float volumeScale = 1f, float panStereo = 0, float pitch = 1)Play AudioClip using the first available channel.

The AudioChannels component is an audio manager to manage the sounds that are played using the Igntion AudioProperties component.

AudioChannels require Unity AudioSource components.

The number of AudioSource components present in the scene determine how many sounds can be played at the same time.

Basic setup requires a GameObject with the AudioChannels component and the number of AudioSource components for each channel you need.

You can then use the AudioChannels Play command to play a sound or use the AudioProperties Play command to play a sound.

Example of the GameObject:

Example scene can be found in Assets/Playniax/Ignition/Examples/01 - Framework/AudioChannels.unity

Example script can be found in Assets/Playniax/Ignition/Examples/01 - Framework/Scripts (MonoBehaviour)/AudioChannels_Example.cs
using UnityEngine; using Playniax.Ignition.Framework; public class AudioChannels_Example : MonoBehaviour { // Ignition sound object. public AudioProperties audioProperties; void Start() { // State to console. Debug.Log(AudioChannels.mute ? "off" : "on"); } public void Play() { // Play sound audioProperties.Play(); } public void Mute() { // Toggle sound AudioChannels.mute = !AudioChannels.mute; // State to console. Debug.Log(AudioChannels.mute ? "off" : "on"); } }
This way sound effects in your game can be turned on or off with just a single command by changing the mute variable to a true or false state.

The SimpleGameUI uses this system too when you toggle sound.

By using this system the SimpleGameUI can control the sound effects and allow them to be played or not.