UI Toolbox logoUI Toolbox

Sounds and window events

WorkspaceAudio plays a sound set for the windows and the controls of a UIDocument. The default sounds need no code.

The Sounds window of the WorkspaceDemo: the sound set, the volume, the controls with default sounds, the USS sounds and the sounds from code

Add sounds to a scene

  1. In the Hierarchy, select the GameObject that has the UIDocument.
  2. In the Inspector, click Add Component, then UI Toolbox > Workspace Audio.
  3. In the Project window, open Assets/UIToolbox/Examples/Audio.
  4. Drag DefaultSounds (or KenneySounds) into the Sounds field of the component.
  5. Set Volume (0 to 1). Press Play. Move the pointer over a button, then click it.

To make your own set: right-click in the Project window, then Create > UI Toolbox > Sound Set. Drag an audio clip into each slot. An empty slot plays nothing. To change one sound of a sample set, select the set and drag another clip into its slot.

The sounds of a set

Sound When
window-open, window-close, minimize, maximize, restore The window state changes, in each workspace of the document. Windows that change together play one sound: the same window sound plays again after 0.1 s (WorkspaceAudio.STATE_INTERVAL).
focus A window gets focus with no state change. An open or a restore plays only its own sound. A click on an MDI tab chip plays focus too.
button A click on a Button.
menu A click on a context menu item, a ToolBarMenu item or a ChoiceList row, and a pick in the list of a dropdown.
toggle A click on a Toggle, a Switch or a RadioButton.
tab A click on a header of a TabView.
dropdown A click on a DropdownField, a PopupField or an EnumField, which opens its list.
slider A Slider or a SliderInt changes its value from the pointer or the keys. At most one sound each 0.08 s (WorkspaceAudio.SLIDER_INTERVAL).
hover The pointer goes over a control that has a click sound. It plays one time while the pointer stays in that control.
notification, error A notification bubble or a MessageBox shows. error is for the Error severity and the Error icon.

Sounds from USS

--tb-sound sets the click sound of an element and its children. --tb-hover-sound sets the hover sound. The value is a name of the set, or a name of its Custom list. "none" plays no sound.

.shop-button { --tb-sound: "coin"; }           /* another click sound */
.quiet-panel { --tb-sound: "none"; }           /* no click sound and no hover sound */
.shop-button { --tb-hover-sound: "none"; }     /* keep the click sound, stop the hover sound */
.card { --tb-hover-sound: "focus"; }           /* a hover sound on an element with no click sound */
.volume-slider { --tb-sound: "tick"; }         /* another sound for the changes of a slider */
Property Default
--tb-sound By control: button, toggle, tab, dropdown, menu. On a slider it is the sound of a value change (slider).
--tb-hover-sound hover on each control that has a click sound. No sound on other elements.

Sounds from code and from bindings

The sample sound sets

Sound set Origin Used in
Assets/UIToolbox/Examples/Audio/DefaultSounds The Toolbox sounds: our own, made for the package. Own sound: confirm. WorkspaceDemo, Styles
Assets/UIToolbox/Examples/Audio/KenneySounds Kenney "Interface Sounds", CC0. Own sound: confirm. WorkspaceDemo, GameMenu, Settings
Examples/Kingdom/KingdomSounds Our own, made for the example. Own sound: coin. Kingdom
Examples/Firefight/FirefightSounds Our own, made for the example. Own sound: hit. Firefight

Open Assets/UIToolbox/Examples/Scenes/WorkspaceDemo.unity and press Play. The Sounds window is open. The window changes the set, the volume and the mute, and it shows the name of each clip that plays. The license of the Kenney clips is in Third Party Notices.md of the package and in Assets/UIToolbox/Examples/Audio/Kenney/License.txt.

Tips:

Window events

Add UI Toolbox > Window Events (WindowEvents) to raise UnityEvents with no code: Opened, Closed, Minimized, Maximized, Restored, Focused and Unfocused. Each event gets the window id. WindowId limits the events to one window; empty means each window. Workspace is the name of the workspace element; empty means the first workspace. A scene object can play an AudioSource or set an Animator trigger from these events.

Both components derive from ToolboxDocumentComponent. It hooks the document root at Start and after each re-enable, and unhooks at OnDisable.