我正在使用aframevr
制作一个vr应用程序,我希望它可以与所有控制器兼容版本一起使用。
这是我的尝试,当我使用智能手机和Daydream捆绑包进行测试时无法使用。
JavaScript:
AFRAME.registerComponent('controller', {
dependencies: ['tracked-controls'],
schema: {
hand: { default: 'right' }
},
init: function () {
let config = this.config,
data = this.data,
self = this.el;
// track all types of controllers
self.setAttribute('daydream-controls', { hand: data.hand, model: false });
self.setAttribute('gearvr-controls', { hand: data.hand, model: false });
self.setAttribute('oculus-touch-controls', { hand: data.hand, model: false });
self.setAttribute('vive-controls', { hand: data.hand, model: false });
// wait for controller to connect
self.addEventListener('controllerconnected', event => {
let controllerConfig = config[event.detail.name];
self.addEventListener(controllerConfig.triggerEvent, () => {
handleTrigger('0');
});
});
},
config: {
'daydream-controls': {
triggerEvent: 'trackpadup'
},
'gearvr-controls': {
triggerEvent: 'trackpadup'
},
'oculus-touch-controls': {
triggerEvent: 'triggerup'
},
'vive-controls': {
triggerEvent: 'triggerup'
}
}
});
HTML:
<a-entity controller></a-entity>
感谢您的帮助。