53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
(function() {
|
|
var messageChannel = 'MESSAGE_CHANNEL_GATE_GAME';
|
|
var SOUND_URL = 'https://hifi-content.s3.amazonaws.com/wadewatts/Ring2.wav?v=' + Date.now();
|
|
var entityID;
|
|
var sound;
|
|
|
|
function sendMessage(message) {
|
|
message.entityID = entityID;
|
|
Messages.sendMessage(
|
|
messageChannel,
|
|
JSON.stringify(message)
|
|
);
|
|
}
|
|
|
|
function onReceivedMessage(channel, message, senderID) {
|
|
try {
|
|
var data = JSON.parse(message);
|
|
} catch (e) {
|
|
print('Error parsing message: ' + message);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
preload: function(id) {
|
|
entityID = id;
|
|
Messages.subscribe(messageChannel);
|
|
Messages.messageReceived.connect(null, onReceivedMessage);
|
|
sound = SoundCache.getSound(SOUND_URL);
|
|
print('Hello Main Gate');
|
|
},
|
|
unload: function(id) {
|
|
Messages.unsubscribe(messageChannel);
|
|
Messages.messageReceived.disconnect(null, onReceivedMessage);
|
|
},
|
|
enterEntity: function(id) {
|
|
var position = Entities.getEntityProperties(entityID, 'position').position;
|
|
var audioProperties = {
|
|
volume: 0.1,
|
|
position: position
|
|
};
|
|
Audio.playSound(sound, audioProperties);
|
|
|
|
sendMessage({
|
|
type: 'GO_THROUGH',
|
|
avatarSessionUUID: MyAvatar.sessionUUID,
|
|
avatarDisplayName: MyAvatar.displayName
|
|
});
|
|
}
|
|
};
|
|
})
|