protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode) { var device = U3DInputDevices.GetDeviceAtXRNode(xRNode.nodeType); float thumb = 0f, index = 0f, middle = 0f; //psotion && rotation xRNode.TryGetPosition(out anchor.position); xRNode.TryGetRotation(out anchor.rotation); OVRInput.Controller touch = OVRInput.Controller.LTouch; if (anchor.type == NodeType.RightHand) { touch = OVRInput.Controller.RTouch; } //grip anchor.gripTouchValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touch); anchor.gripPressed = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, touch); middle = anchor.gripTouchValue; //trigger anchor.triggerTouchValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, touch); anchor.triggerPressed = OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, touch); index = anchor.triggerTouchValue; //system device.TryGetFeatureValue(CommonUsages.menuButton, out anchor.systemPressed); anchor.systemTouchValue = 0f; if (anchor.systemPressed) { anchor.systemTouchValue = 1f; } thumb = Mathf.Max(thumb, anchor.systemTouchValue); //primary anchor.primaryPressed = OVRInput.Get(OVRInput.Button.One, touch); anchor.primaryTouch = OVRInput.Get(OVRInput.Touch.One, touch); anchor.primaryTouchValue = 0f; if (anchor.primaryTouch) { anchor.primaryTouchValue = 0.5f; } if (anchor.primaryPressed) { anchor.primaryTouchValue = 1.0f; } thumb = Mathf.Max(thumb, anchor.primaryTouchValue); //secondary anchor.secondaryPressed = OVRInput.Get(OVRInput.Button.Two, touch); anchor.secondaryTouch = OVRInput.Get(OVRInput.Touch.Two, touch); anchor.secondaryTouchValue = 0f; if (anchor.secondaryTouch) { anchor.secondaryTouchValue = 0.5f; } if (anchor.secondaryPressed) { anchor.secondaryTouchValue = 1.0f; } thumb = Mathf.Max(thumb, anchor.secondaryTouchValue); //primary2DAxis anchor.primary2DAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, touch); anchor.primary2DAxisPressed = OVRInput.Get(OVRInput.Button.PrimaryThumbstick, touch); anchor.primary2DAxisTouch = OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, touch); thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f); thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f); //secondary2DAxis anchor.secondary2DAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick, touch); thumb = Mathf.Max(thumb, anchor.secondary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f); thumb = thumb > 0.06f ? thumb : 0; //fingers anchor.fingerCurls[0] = thumb; anchor.fingerCurls[1] = index; anchor.fingerCurls[2] = middle; anchor.fingerCurls[3] = middle; anchor.fingerCurls[4] = middle; anchor.handPoseChanged = true; }
protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode) { //base.UpdateHandNodeState(hand, ref xRNode); float thumb = 0f, index = 0f, middle = 0f; //psotion && rotation xRNode.TryGetPosition(out anchor.position); xRNode.TryGetRotation(out anchor.rotation); var inputSource = SteamVR_Input_Sources.LeftHand; string skeletonHandName = "SkeletonLeftHand"; if (anchor.type == NodeType.RightHand) { inputSource = SteamVR_Input_Sources.RightHand; skeletonHandName = "skeletonRightHand"; } //SteamVR_Action_Boolean key_MenuKey = SteamVR_Input.GetBooleanAction("MenuKey"); //SteamVR_Action_Boolean key_SystemKey = SteamVR_Input.GetBooleanAction("SystemKey"); //trigger SteamVR_Action_Boolean triggerPressed = SteamVR_Input.GetBooleanAction("Trigger"); //SteamVR_Action_Single triggerTouchValue = SteamVR_Input.GetSingleAction("triggerTouchValue"); anchor.triggerPressed = triggerPressed.GetState(inputSource); anchor.triggerTouchValue = Mathf.Lerp(anchor.triggerTouchValue, anchor.triggerPressed ? 1f : 0f, Time.deltaTime * 5); index = anchor.triggerTouchValue; //grip SteamVR_Action_Boolean gripPressed = SteamVR_Input.GetBooleanAction("SideTrigger"); //SteamVR_Action_Single gripTouchValue = SteamVR_Input.GetSingleAction("gripTouchValue"); anchor.gripPressed = gripPressed.GetState(inputSource); anchor.gripTouchValue = Mathf.Lerp(anchor.gripTouchValue, anchor.gripPressed ? 1f : 0f, Time.deltaTime * 5); middle = anchor.gripTouchValue; //primary2DAxis SteamVR_Action_Vector2 primary2DAxis = SteamVR_Input.GetVector2Action("ThumbStick"); SteamVR_Action_Boolean primary2DAxisClick = SteamVR_Input.GetBooleanAction("PadDown"); anchor.primary2DAxis = primary2DAxis.GetAxis(inputSource); anchor.primary2DAxisTouch = anchor.primary2DAxis.sqrMagnitude > 0.02f; anchor.primary2DAxisPressed = primary2DAxisClick.GetState(inputSource); thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f); thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f); //primary SteamVR_Action_Boolean primaryPressed = SteamVR_Input.GetBooleanAction("BKey"); anchor.primaryPressed = primaryPressed.GetState(inputSource); anchor.primaryTouchValue = (anchor.primaryPressed) ? 1f : 0f; thumb = Mathf.Max(thumb, anchor.primaryTouchValue); //secondary SteamVR_Action_Boolean secondaryPressed = SteamVR_Input.GetBooleanAction("AKey"); anchor.secondaryPressed = secondaryPressed.GetState(inputSource); anchor.secondaryTouchValue = (anchor.secondaryPressed) ? 1f : 0f; thumb = Mathf.Max(thumb, anchor.secondaryTouchValue); //fingers var skeletonHand = SteamVR_Input.GetAction <SteamVR_Action_Skeleton>(skeletonHandName); if (skeletonHand.poseIsValid) { anchor.handPoseChanged = skeletonHand.poseChanged; anchor.fingerCurls[0] = skeletonHand.thumbCurl; anchor.fingerCurls[1] = skeletonHand.indexCurl; anchor.fingerCurls[2] = skeletonHand.middleCurl; anchor.fingerCurls[3] = skeletonHand.ringCurl; anchor.fingerCurls[4] = skeletonHand.pinkyCurl; } else { anchor.handPoseChanged = true; anchor.fingerCurls[0] = thumb; anchor.fingerCurls[1] = index; anchor.fingerCurls[2] = middle; anchor.fingerCurls[3] = middle; anchor.fingerCurls[4] = middle; } }