标签:bug trigger update 体会 菜单 called rac dup 设备
写这篇文章的原因主要是因为现在虚拟现实非常的火爆但目前主流的虚拟现实设备(HTC VIVE)的教程却少的可怜,这个我深有体会。所以,我想将我平时开发中遇到的问题以及解决方法记录下来,分享给大家,若其中有什么错误或者大家有什么更好的方案也请大家指出,大家互相学习,哈哈。
好了直接上代码。
using UnityEngine;
using System.Collections;
public class shoubingkongzhi : MonoBehaviour {
///
/// 手柄
///
SteamVR_TrackedObject tracked;
void Awake()
{
//获取手柄
tracked = GetComponent<steamvr_trackedobject>();
}
// Update is called once per frame
void FixedUpdate()
{
var device = SteamVR_Controller.Input((int)tracked.index);
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
{
Debug.Log("按下圆盘");
}
else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("按下扳机键");
}
else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("按下手柄侧键");
}
else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
{
Debug.Log("按下手柄菜单键");
}
else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
{
Debug.Log("按下手柄菜单键");
}
}
}
Debug.Log("按下手柄菜单键");}}}
以上都是HTC VIVE手柄中按键按下的代码。其他还有:
按键松开—device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger);
按键长安—device.GetPress(SteamVR_Controller.ButtonMask.Trigger);
按键按下还有另一种方式,但是我自我感觉用着很别扭,没上述的好。device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu);
其他用法与GetPressDown()类似。
转载自:http://www.52vr.com/article-391-1.html
标签:bug trigger update 体会 菜单 called rac dup 设备
原文地址:http://www.cnblogs.com/mantouyefan/p/6090720.html