Sound and Audio
LUI can play UI interaction sounds with no per-element wiring. The theme supplies one clip per
interaction type, and you opt an element in with a sound-* utility class (pointer driven) or
play a sound imperatively from code.
Theme Clips
LuiTheme exposes one clip per interaction, a master volume, and a global mute:
| Theme field | Used for |
|---|---|
soundHover | Pointer enters a sound-hover / sound-button element |
soundClick | A sound-click / sound-button element is clicked |
soundOpen | Open interaction, usually played via Lui.PlaySound(LuiSound.Open) |
soundClose | Close interaction, including modal X and sound-close |
soundConfirm | Confirm interaction, including Confirm dialog accept and sound-confirm |
soundCancel | Cancel interaction, including Confirm dialog cancel and sound-cancel |
soundVolume | Master volume from 0 to 1 for all interaction sounds |
muteSounds | Suppresses every interaction sound when enabled |
All clips play through a single shared, persistent AudioSource created on first use, so there is
no setup in the scene.
Utility Classes
Add a sound-* class to map an element’s pointer interactions to a theme clip:
| Utility | Behavior |
|---|---|
sound-button | Plays hover on pointer enter and click on click; the common path for buttons |
sound-click | Plays click on click |
sound-hover | Plays hover on pointer enter |
sound-confirm | Plays confirm on click |
sound-cancel | Plays cancel on click |
sound-open | Plays open on click |
sound-close | Plays close on click |
sound-none | Suppresses sounds on this element |
Lui.Button("Play", "px-4 py-2 rounded-lg bg-primary sound-button", OnPlay)
Lui.Div("p-4 sound-hover").OnClick(Select)Sounds are suppressed automatically on disabled and loading elements, matching their other
interactions.
Fluent Equivalent
.Sound(click, hover) sets the same thing without class tokens:
Lui.Button("Confirm", classes, OnConfirm).Sound(LuiSound.Confirm)
Lui.Button("Play", classes, OnPlay).Sound(LuiSound.Click, LuiSound.Hover) // == sound-buttonImperative Playback
For sounds that aren’t pointer driven - most commonly playing Open when an overlay is toggled
open from code - call Lui.PlaySound:
void OpenMenu()
{
_menuOpen.Value = true;
Lui.PlaySound(LuiSound.Open);
}Built-in Overlay Sounds
The built-in overlays are pre-wired so they sound automatically once the matching theme clips are assigned:
| Overlay surface | Sound behavior |
|---|---|
| Modal X close button | Plays Close |
LuiOverlay.Confirm | Plays Confirm on accept and Cancel on the cancel button |
Custom LuiModalActions | Accept a sound: argument, such as LuiModalAction.Primary(label, onClick, sound: LuiSound.Confirm) |
Sound Values
| Value | Meaning |
|---|---|
None | No sound |
Hover | Theme hover clip |
Click | Theme click clip |
Open | Theme open clip |
Close | Theme close clip |
Confirm | Theme confirm clip |
Cancel | Theme cancel clip |
Demo
See ReadySoundComponent (the Sound tab in the components showcase) for the sound-* classes,
the imperative Lui.PlaySound(LuiSound.Open) button, a disabled-silences toggle, and a Confirm
dialog wired for Confirm/Cancel sounds. Assign clips to the active theme to hear them.