UI Toolbox logoUI Toolbox

AudioSettingsPanel and AudioOptions

An AudioSettingsPanel is an audio settings screen. It is a PropertyGrid of AudioOptions with Defaults, Revert and Apply buttons. It has the members of the SettingsPanel base (see Custom settings panels), and Mixer.

The Audio tab of the Settings screen of the GameMenu example: an AudioSettingsPanel without its buttons, and the test sound buttons of the sample

<tb:AudioSettingsPanel prefs-key="mygame.audio" />
// The mixer of the Music, Effects and Voice volumes
var panel = root.Q<AudioSettingsPanel>();
panel.Mixer = myMixer;
Category Option Sets
Volume Master AudioListener.volume. It works without a mixer.
Volume Music, Effects, Voice The exposed mixer parameters MusicVolume, EffectsVolume and VoiceVolume, in decibels. Without a mixer, these rows are disabled.
Volume Interface ToolboxAudio.Volume: the sounds of the windows, the buttons and the menus.
Options Mute AudioListener.volume 0. Master keeps its value.
Options Mute in background AudioListener.pause while the game does not have the focus.

The volumes are percents. AudioOptions.ToDecibels(percent) gives 0 dB at 100, about -6 dB at 50 and -80 dB (SILENT_DB) at 0. ToPercent(decibels) is the reverse.

How to set up the mixer:

  1. In the Project window, right-click a folder and click Create > Audio Mixer.
  2. Open the mixer (double-click it). In the Groups list, click + three times. Name the groups Music, Effects and Voice.
  3. Click the Music group. In the Inspector, right-click Volume and click Expose 'Volume (of Music)' to script.
  4. Do step 3 for Effects and Voice.
  5. In the mixer window, click Exposed Parameters (top right). Rename the three parameters to MusicVolume, EffectsVolume and VoiceVolume.
  6. On each AudioSource of the game, set Output to its group.
  7. Set the mixer on the panel: panel.Mixer = mixer, or AudioOptions.Mixer = mixer. The GameMenu example has a Mixer field on its SettingsController.

AudioOptions works without the panel:

// At the start of the game: set the saved options
AudioOptions.Mixer = mixer;
AudioOptions.LoadSaved("mygame.audio").Apply();

Tips: