SteamVR 控制监听
using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; using Valve.VR.Extras; /// <summary> /// /// 所有输入的监听 /// </summary> public class AllInput : MonoBehaviour { //public SteamVR_LaserPointer Left; //public SteamVR_LaserPointer Right; private SteamVR_Action_Boolean m_InteractUI; private SteamVR_Action_Single m_Squeeze; private SteamVR_Action_Vector2 m_Touch; private SteamVR_Action_Pose m_Pose; private SteamVR_Action_Boolean m_Menu; private SteamVR_Action_Boolean m_Hold; private SteamVR_Action_Boolean m_Teleport; private SteamVR_Action_Boolean m_Y, m_X, m_B, m_A; public bool Y, X, B, A; /// <summary> /// 左手射线 /// </summary> public Ray LeftRay; /// <summary> /// 右手射线 /// </summary> public Ray RightRay; /// <summary> /// 左手位置 /// </summary> public Vector3 LeftPostion; /// <summary> /// 右手位置 /// </summary> public Vector3 RightPostion; /// <summary> /// 右手旋转 /// </summary> public Vector3 RightQuaternion; /// <summary> /// 左手旋转 /// </summary> public Vector3 LeftQuaternion; /// <summary> /// 右手扳机开始按下 /// </summary> public bool RightPressDownStart=false; /// <summary> /// 右手扳机 开始松开 /// </summary> public bool RightPressUpStart = false; /// <summary> /// 左手扳机 松开 /// </summary> public bool LeftPressUpStart = false; /// <summary> /// 左手扳机 按下 /// </summary> public bool LeftPressDownStart = false; /// <summary> /// 左手扳机 持续按住 /// </summary> public bool LeftPressDownTrigger; /// <summary> /// 右手扳机 按住 /// </summary> public bool RightPressDownTrigger; /// <summary> /// 有一个扳机 按住 /// </summary> public bool OnePressDownTrigger; /// <summary> /// 有一个扳机 按下 /// </summary> public bool OnePressDownStart; /// <summary> /// 有一个扳机 松开 /// </summary> public bool OnePressUpStart; /// <summary> /// 左手触碰版松开 /// </summary> public bool LeftTouchPressUp; /// <summary> /// 右手触碰版松开 /// </summary> public bool RightTouchPressUp; /// <summary> /// 一个触碰版松开 /// </summary> public bool OneTouchPressUp; /// <summary> /// 左手触碰版开始按下 /// </summary> public bool LeftTouchPressDown; /// <summary> /// 右手触碰版开始按下 /// </summary> public bool RightTouchPressDown; /// <summary> /// 一个触碰版开始按下 /// </summary> public bool OneTouchPressDown; /// <summary> /// 左手触碰版按下 /// </summary> public bool LeftTouchPress; /// <summary> /// 右手触碰版按下 /// </summary> public bool RightTouchPress; /// <summary> /// 一个触碰版触碰 /// </summary> public bool OneTouchPress; /// <summary> /// 左手触碰版位置 /// </summary> public Vector2 LeftTouch; /// <summary> /// 右手触碰版位置 /// </summary> public Vector2 RightTouch; /// <summary> /// 一个触碰版正在被触碰位置 /// </summary> public Vector2 OneTouch; /// <summary> /// 菜单是否开启 /// </summary> public bool Menu; /// <summary> /// 有一个扳机被拉动的程度 /// </summary> public float OneSqueeze; /// <summary> /// 左手扳机拉动程度 /// </summary> public float LeftSqueeze; /// <summary> /// 右手扳机键拉动程度 /// </summary> public float RightSqueeze; /// <summary> /// 左手握持键是否按住 /// </summary> public bool LeftHold; /// <summary> /// 右手握持键是否按住 /// </summary> public bool RightHold; /// <summary> /// 有一个我握持键被按住 /// </summary> public bool OneHold; /// <summary> /// 鼠标左键 /// </summary> public bool LeftMouseDown=false; /// <summary> /// 鼠标左键抬起 /// </summary> public bool LeftMouseUp = false; /// <summary> /// 鼠标右键 /// </summary> public bool RightMouseDown=false; /// <summary> /// 左手触控板的偏移量 /// </summary> public Vector2 LeftOffsetPostion; /// <summary> /// 右手触控板的偏移量 /// </summary> public Vector2 RightOffsetPostion; private Vector2 LastLeftPostion; private Vector2 LastRightPostion; void Start() { m_Menu = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Menu"); m_Squeeze =SteamVR_Input.GetAction<SteamVR_Action_Single>("Squeeze"); m_InteractUI = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("InteractUI"); m_Touch = SteamVR_Input.GetAction<SteamVR_Action_Vector2>("Touch"); m_Pose= SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose"); m_Hold = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("GrabGrip"); m_Teleport= SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Teleport"); m_Y = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Y"); m_X = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("X"); m_B = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("B"); m_A = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("A"); } // Update is called once per frame void Update() { //LeftPostion = Left.gameObject.transform.position; //RightPostion = Right.gameObject.transform.position; //RightQuaternion = Right.gameObject.transform.eulerAngles; //LeftQuaternion = Left.gameObject.transform.eulerAngles; LeftTouchPress = m_Teleport.GetState(SteamVR_Input_Sources.LeftHand); RightTouchPress = m_Teleport.GetState(SteamVR_Input_Sources.RightHand); OneTouchPress = m_Teleport.GetState(SteamVR_Input_Sources.Any); LeftTouchPressDown = m_Teleport.GetStateDown(SteamVR_Input_Sources.LeftHand); RightTouchPressDown = m_Teleport.GetStateDown(SteamVR_Input_Sources.RightHand); OneTouchPressDown = m_Teleport.GetStateDown(SteamVR_Input_Sources.Any); LeftTouchPressUp = m_Teleport.GetStateUp(SteamVR_Input_Sources.LeftHand); RightTouchPressUp = m_Teleport.GetStateUp(SteamVR_Input_Sources.RightHand); OneTouchPressUp = m_Teleport.GetStateUp(SteamVR_Input_Sources.Any); LeftPressDownTrigger = m_InteractUI.GetState(SteamVR_Input_Sources.LeftHand); RightPressDownTrigger = m_InteractUI.GetState(SteamVR_Input_Sources.RightHand); OnePressDownTrigger = m_InteractUI.GetState(SteamVR_Input_Sources.Any); LeftPressUpStart = m_InteractUI.GetStateUp(SteamVR_Input_Sources.LeftHand); RightPressUpStart = m_InteractUI.GetStateUp(SteamVR_Input_Sources.RightHand); OnePressUpStart = m_InteractUI.GetStateUp(SteamVR_Input_Sources.Any); LeftPressDownStart = m_InteractUI.GetStateDown(SteamVR_Input_Sources.LeftHand); RightPressDownStart = m_InteractUI.GetStateDown(SteamVR_Input_Sources.RightHand); OnePressDownStart = m_InteractUI.GetStateDown(SteamVR_Input_Sources.Any); LeftSqueeze = m_Squeeze.GetAxis(SteamVR_Input_Sources.LeftHand); RightSqueeze = m_Squeeze.GetAxis(SteamVR_Input_Sources.RightHand); OneSqueeze = m_Squeeze.GetAxis(SteamVR_Input_Sources.Any); LeftTouch = m_Touch.GetAxis(SteamVR_Input_Sources.LeftHand); RightTouch = m_Touch.GetAxis(SteamVR_Input_Sources.RightHand); OneTouch = m_Touch.GetAxis(SteamVR_Input_Sources.Any); Menu = m_Menu.GetState(SteamVR_Input_Sources.Any); LeftHold = m_Hold.GetState(SteamVR_Input_Sources.LeftHand); RightHold = m_Hold.GetState(SteamVR_Input_Sources.RightHand); OneHold = m_Hold.GetState(SteamVR_Input_Sources.Any); LeftMouseDown = Input.GetMouseButtonDown(0); LeftMouseUp = Input.GetMouseButtonUp(0); RightMouseDown = Input.GetMouseButtonDown(1); if (LastLeftPostion!=Vector2.zero) { LeftOffsetPostion += LeftTouch - LastLeftPostion; } if (LastRightPostion != Vector2.zero) { RightOffsetPostion += RightTouch - LastRightPostion; } LastLeftPostion = LeftTouch; LastRightPostion = RightTouch; if (LastLeftPostion==Vector2.zero) { LeftOffsetPostion = Vector2.zero; } if (LastRightPostion == Vector2.zero) { RightOffsetPostion = Vector2.zero; } Y = m_Y.GetStateDown(SteamVR_Input_Sources.Any); X = m_X.GetStateDown(SteamVR_Input_Sources.Any); B = m_B.GetStateDown(SteamVR_Input_Sources.Any); A = m_A.GetStateDown(SteamVR_Input_Sources.Any); } }