1喂饥、手柄的詳細(xì)介紹。
手柄對(duì)象一欄: http://www.reibang.com/p/c28fbf480cff
2蓄坏、獲取手柄上按鍵的對(duì)應(yīng)信息
2-1 :獲取手柄編號(hào)
// 手柄組件
Left = GetComponent<SteamVR_TrackedObject>();
// 獲取手柄編號(hào)(左手柄 == 2)
Debug.Log((int)Left.index);
在手柄上掛載此腳本
打印結(jié)果
2-2 : 獲取扳機(jī)按鍵
// 按下了扳機(jī)按鈕調(diào)用
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("trigger");
}
第二種方式也是Ok的
if (device.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
{
print("123");
}
Paste_Image.png
// 按下手柄左右的對(duì)稱按鈕調(diào)用董习,而且調(diào)用頻率跟刷新頻率一致
if (device.GetTouch(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("Grip");
}
Paste_Image.png
2-3:獲取grid
// 按下手柄左右的對(duì)稱按鈕調(diào)用,而且調(diào)用頻率跟刷新頻率一致
if (device.GetTouch(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("Grip");
}
2-4:獲取圓盤
Paste_Image.png
// 當(dāng)手放置在觸摸圓盤上的時(shí)候調(diào)用
if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
{
Debug.Log("touchpad");
}
// 當(dāng)手放置在觸摸圓盤上的時(shí)候調(diào)用
if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
{
Debug.Log("touchpad");
// 獲取觸摸板上的坐標(biāo)
Vector2 pad = device.GetAxis();
// Debug.Log("按下了" + pad);
// 轉(zhuǎn)換角度
Vector3 cross = Vector3.Cross(new Vector2(1, 0), pad);
float angle = Vector2.Angle(new Vector2(1, 0), pad);
float ang = cross.z > 0 ? -angle : angle;
Debug.Log(ang);
//根據(jù)角度來判斷上下左右四個(gè)范圍
}
2-5:關(guān)于Axis
// 按下面板的時(shí)候打印
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
{
Debug.Log("Axis0");
}
// 按下扳機(jī)鍵的時(shí)候打印
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
{
Debug.Log("Axis1");
}
其他的Axis2,3,4暫時(shí)還沒有什么能夠觸發(fā)
3抠刺、手柄的震動(dòng)
//左手震動(dòng)
var device1 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
SteamVR_Controller.Input(device1).TriggerHapticPulse(2000);
// 獲取左右手柄的標(biāo)志
var device2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
// 設(shè)置獲取手柄的震動(dòng)值
SteamVR_Controller.Input(device2).TriggerHapticPulse(100);