我在 Unity 中啟用了 OpenXR VR 模式。

然后我啟用了 HTC Vive 互動組態檔和其他

之后我可以看到世界,我可以獲得 HTC Vive 控制器的手部位置,但我無法獲得任何輸入,例如如何獲得觸發按鈕按下事件?

我正在使用以下代碼:
private UnityEngine.XR.InputDevice inputDevice;
public bool isIndexTriggerPressed()
{
bool triggerValue = false;
inputDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.triggerButton, out triggerValue);
if ((!previousIndexTriggerPressed) && (triggerValue))
{
previousIndexTriggerPressed = triggerValue;
return true;
}
previousIndexTriggerPressed = triggerValue;
return false;
}
這是正確的代碼嗎?,我怎樣才能獲得觸發按下事件?
uj5u.com熱心網友回復:
我讓它作業的唯一方法是直接使用 SteamVR Unity 插件。
我將在 SteamVR/Prefabs 目錄中本地化的“[CameraRig]”物件拖到我的場景中。
我使用以下代碼來獲取輸入:
private GameObject controller;
private SteamVR_Input_Sources inputDevice = SteamVR_Input_Sources.LeftHand;
public void setInputDevice(SteamVR_Input_Sources inputDevice)
{
this.inputDevice = inputDevice;
}
public void setController(GameObject controller)
{
this.controller = controller;
}
public GameObject getController()
{
return controller;
}
public Vector2 getTrackPad()
{
return SteamVR_Actions.default_Trackpad.GetAxis(inputDevice);
}
public bool isHandTrigger()
{
return SteamVR_Actions.default_GrabGrip.GetState(inputDevice);
}
public bool isHandTriggerPressed()
{
return SteamVR_Actions.default_GrabGrip.GetStateDown(inputDevice);
}
public bool isHandTriggerReleased()
{
return SteamVR_Actions.default_GrabGrip.GetStateUp(inputDevice);
}
public bool isIndexTrigger()
{
return SteamVR_Actions.default_GrabPinch.GetState(inputDevice);
}
public bool isIndexTriggerPressed()
{
return SteamVR_Actions.default_GrabPinch.GetStateDown(inputDevice);
}
public bool isIndexTriggerReleased()
{
return SteamVR_Actions.default_GrabPinch.GetStateUp(inputDevice);
}
public bool isMenu()
{
return SteamVR_Actions.default_Menu.GetState(inputDevice);
}
public bool isMenuPressed()
{
return SteamVR_Actions.default_Menu.GetStateDown(inputDevice);
}
public bool isMenuReleased()
{
return SteamVR_Actions.default_Menu.GetStateUp(inputDevice);
}
不要忘記系結視窗 -> SteamVR 輸入


轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329230.html
標籤:统一3d 输入 HTC Vive 蒸汽虚拟机 打开xr
上一篇:unity如何用按鈕讓物體移動
