-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvive-control-menu.js
40 lines (35 loc) · 1.29 KB
/
vive-control-menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
AFRAME.registerComponent('vive-control-menu', {
schema: {
controllerID: { default: 'menu' }
},
init: function() {
var menuElement = document.createElement("a-entity");
menuElement.id = 'menuElement';
menuElement.innerHTML = '<a-entity id="menuElementText" text="value: fly-hand;" position="0.425 0.1 0"></a-entity>';
this.el.appendChild(menuElement);
var self = this;
var controller = document.getElementById(this.data.controllerID);
controller.addEventListener('trackpaddown', function(evt) {
dispatchChangeEvent(self);
});
controller.addEventListener('triggerdown', function(evt) {
changeControlText(self);
})
}
});
function dispatchChangeEvent(self) {
var menuText = document.getElementById('menuElementText').getAttribute('text');
var event = new CustomEvent('controlchange', {detail: menuText.value, bubbles: true});
self.el.dispatchEvent(event);
};
function changeControlText(self) {
var menuText = document.getElementById('menuElementText').getAttribute('text');
if (menuText.value === 'fly-hand') {
menuText.value = 'fly-head';
} else if (menuText.value === 'fly-head') {
menuText.value = 'laser';
} else {
menuText.value = 'fly-hand';
}
document.getElementById('menuElementText').setAttribute('text', menuText);
}