UI Toolbox logoUI Toolbox
Support

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.

An AudioSettingsPanel with Master, Music, Effects, Voice and Interface volume sliders, a Mute option and Defaults, Revert and Apply buttons, next to an In effect readout with test sound buttonsAn AudioSettingsPanel with Master, Music, Effects, Voice and Interface volume sliders, a Mute option and Defaults, Revert and Apply buttons, next to an In effect readout with test sound buttons

<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.

Each row is a field of AudioOptions: Master, Music, Effects, Voice and Interface (0 to 100), Mute and MuteInBackground. The Grid of the panel is its PropertyGrid.

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:

The AudioSettingsPanelDemo scene shows the panel with no setup next to the volumes in effect and test sounds, a mixer and a subclass with a volume of its own, what it saves and loads, Apply, Revert and the events, the keys and the gamepad, and the panel in a parchment and a terminal look.