Unity HTCVR 设备手柄控制
Posted dgjs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity HTCVR 设备手柄控制相关的知识,希望对你有一定的参考价值。
using System.Collections; using System.Collections.Generic; using UnityEngine; using HTC.UnityPlugin.Vive; using UnityEngine.SceneManagement; public class HandFunction : MonoBehaviour { public static HandFunction hand_function; public GameObject RightRay; public bool Ray_bool; //射线开关 public bool Ray_Canvas; //ui开关 private void Awake() { hand_function = this; } void Start() { RightRay.SetActive(false); Ray_Canvas = false; } void Update() { PressMenuKey(); PressTriggerKey(); PressGripKey(); } /// <summary> /// 按下应用键 /// </summary> void PressMenuKey() { if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Menu)/*|| ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Menu)*/) { Ray_bool = !Ray_bool; RightRay.SetActive(Ray_bool); } if (ViveInput.GetPressDown(HandRole.LeftHand,ControllerButton.Menu)) { if (SceneVR.scene_vr.UiOpen==true) { Ray_Canvas = !Ray_Canvas; SceneVR.scene_vr.UICanvasVR.SetActive(Ray_Canvas); } } } /// <summary> /// 按下扳机键 /// </summary> void PressTriggerKey() { if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger)|| ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Trigger)) { SceneVR.scene_vr.IsRayOpenToolVR = true; } if (ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Trigger)|| ViveInput.GetPressUp(HandRole.LeftHand, ControllerButton.Trigger)) { SceneVR.scene_vr.IsRayOpenToolVR = false; } } /// <summary> /// 按下圆盘键 /// </summary> void PressPadKey() { if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Pad)) { } } /// <summary> /// 按下侧握键 /// </summary> void PressGripKey() { if (ViveInput.GetPressDown(HandRole.LeftHand,ControllerButton.Grip)) { SceneVR.scene_vr.Rerouting(); SceneVR.scene_vr.IsaniOpen(); SceneVR.scene_vr.IsAniOpen = false; } } }
以上是关于Unity HTCVR 设备手柄控制的主要内容,如果未能解决你的问题,请参考以下文章