mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-07 23:24:10 +02:00
Add button sounds
This commit is contained in:
parent
4268297769
commit
f4a8dc49e9
4 changed files with 35 additions and 0 deletions
BIN
scripts/system/assets/sounds/button-click.wav
Normal file
BIN
scripts/system/assets/sounds/button-click.wav
Normal file
Binary file not shown.
BIN
scripts/system/assets/sounds/button-hover.wav
Normal file
BIN
scripts/system/assets/sounds/button-hover.wav
Normal file
Binary file not shown.
|
@ -17,6 +17,7 @@
|
|||
|
||||
var // EventBridge
|
||||
READY_MESSAGE = "ready", // Engine <== Dialog
|
||||
HOVER_MESSAGE = "hover", // Engine <== Dialog
|
||||
MUTE_MESSAGE = "mute", // Engine <=> Dialog
|
||||
BUBBLE_MESSAGE = "bubble", // Engine <=> Dialog
|
||||
EXPAND_MESSAGE = "expand", // Engine <== Dialog
|
||||
|
@ -57,6 +58,12 @@
|
|||
}));
|
||||
}
|
||||
|
||||
function onButtonHover() {
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: HOVER_MESSAGE
|
||||
}));
|
||||
}
|
||||
|
||||
function onBubbleButtonClick() {
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: BUBBLE_MESSAGE
|
||||
|
@ -97,6 +104,9 @@
|
|||
|
||||
connectEventBridge();
|
||||
|
||||
muteButton.addEventListener("mouseenter", onButtonHover, false);
|
||||
bubbleButton.addEventListener("mouseenter", onButtonHover, false);
|
||||
expandButton.addEventListener("mouseenter", onButtonHover, false);
|
||||
muteButton.addEventListener("click", onMuteButtonClick, true);
|
||||
bubbleButton.addEventListener("click", onBubbleButtonClick, true);
|
||||
expandButton.addEventListener("click", onExpandButtonClick, true);
|
||||
|
|
|
@ -86,6 +86,7 @@
|
|||
|
||||
// EventBridge
|
||||
READY_MESSAGE = "ready", // Engine <== Dialog
|
||||
HOVER_MESSAGE = "hover", // Engine <== Dialog
|
||||
MUTE_MESSAGE = "mute", // Engine <=> Dialog
|
||||
BUBBLE_MESSAGE = "bubble", // Engine <=> Dialog
|
||||
EXPAND_MESSAGE = "expand", // Engine <== Dialog
|
||||
|
@ -99,11 +100,20 @@
|
|||
HIFI_OBJECT_MANIPULATION_CHANNEL = "Hifi-Object-Manipulation",
|
||||
avatarScale = 1,
|
||||
|
||||
// Sounds
|
||||
HOVER_SOUND = "./assets/sounds/button-hover.wav",
|
||||
HOVER_VOLUME = 0.5,
|
||||
CLICK_SOUND = "./assets/sounds/button-click.wav",
|
||||
CLICK_VOLUME = 0.8,
|
||||
hoverSound = SoundCache.getSound(Script.resolvePath(HOVER_SOUND)),
|
||||
clickSound = SoundCache.getSound(Script.resolvePath(CLICK_SOUND)),
|
||||
|
||||
// Hands
|
||||
LEFT_HAND = 0,
|
||||
RIGHT_HAND = 1,
|
||||
NO_HAND = 2,
|
||||
HAND_NAMES = ["LeftHand", "RightHand"],
|
||||
|
||||
DEBUG = false;
|
||||
|
||||
// #region Utilities =======================================================================================================
|
||||
|
@ -149,6 +159,14 @@
|
|||
return hand === LEFT_HAND ? RIGHT_HAND : LEFT_HAND;
|
||||
}
|
||||
|
||||
function playSound(sound, volume) {
|
||||
Audio.playSound(sound, {
|
||||
position: proxyHand === LEFT_HAND ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition(),
|
||||
volume: volume,
|
||||
localOnly: true
|
||||
});
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region Communications ==================================================================================================
|
||||
|
@ -187,16 +205,23 @@
|
|||
updateMutedStatus();
|
||||
updateBubbleStatus();
|
||||
break;
|
||||
case HOVER_MESSAGE:
|
||||
// Audio feedback.
|
||||
playSound(hoverSound, HOVER_VOLUME);
|
||||
break;
|
||||
case MUTE_MESSAGE:
|
||||
// Toggle mute.
|
||||
playSound(clickSound, CLICK_VOLUME);
|
||||
Audio.muted = !Audio.muted;
|
||||
break;
|
||||
case BUBBLE_MESSAGE:
|
||||
// Toggle bubble.
|
||||
playSound(clickSound, CLICK_VOLUME);
|
||||
Users.toggleIgnoreRadius();
|
||||
break;
|
||||
case EXPAND_MESSAGE:
|
||||
// Expand tablet;
|
||||
playSound(clickSound, CLICK_VOLUME);
|
||||
setState(PROXY_EXPANDING, NO_HAND);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue