private void LateUpdate() { bool isHandClose = handUI.isHandClose(hand); bool isGrabbedByOtherHand = handUI.pinched && handUI.closestHand == hand.otherHand(); bool isTwoHandedAllowed = handUI.twoHandedTRS; if (isTwoHandedAllowed) { if (!shown && isHandClose && !hand.isPinched()) { Show(); shown = true; } if (shown && (!isHandClose || hand.isPinched())) { Hide(); shown = false; } } else { if ((!isHandClose || isGrabbedByOtherHand || hand.isPinched()) && shown) { Hide(); shown = false; } if (!isGrabbedByOtherHand && !shown && isHandClose && !hand.isPinched()) { Show(); shown = true; } } if (shown) { transform.position = handUI.ClosestPointOnCircleToHand(hand); } }
private void Update() { closestHand = null; //find closest hand dL = HandDistance(HandUIManager.handLeft); dR = HandDistance(HandUIManager.handRight); if (dL <= dR) { closestHand = HandUIManager.handLeft; } else if (dR < dL) { closestHand = HandUIManager.handRight; } closestHandDist = Mathf.Min(dL, dR); dist = closestHandDist; handIsClose = dist < hoverDistance * hoverDistance; if (handIsClose && !hovered && canBeHovered && !isClosestPinching()) { BeginHover(); } if (!handIsClose && !pinched && hovered) { EndHover(); } reset = false; if (hovered && !pinched && isClosestPinching() && !isClosestHandHolding()) { BeginPinch(); } if (pinched && !isClosestPinching()) { EndPinch(); } if (!bothHandsPinched && pinched && closestHand.otherHand().isPinched() && isHandClose(closestHand.otherHand())) { // start double pinch bothHandsPinched = true; onGrabDistanceBetweenHands = Vector3.Distance(HandUIManager.pinchLeft.pose.position, HandUIManager.pinchRight.pose.position); onGrabScale = transform.localScale; onGrabEulerAngles = transform.eulerAngles; var midpoint = (HandUIManager.pinchLeft.pose.position + HandUIManager.pinchLeft.pose.position) / 2; prevMidpointPos = midpoint; deltaAngle = 0; reset = true; onGrabMidpointOffset = midpoint - transform.position; onGrabRightToLeft = HandUIManager.pinchLeft.pose.position - HandUIManager.pinchRight.pose.position; onGrabRightToLeft.y = 0; } if (bothHandsPinched && !(closestHand.isPinched() && closestHand.otherHand().isPinched())) { //end double pinch bothHandsPinched = false; onGrabMidpointOffset = HandPointerPos(closestHand) - transform.position; } if (pinched) { var currentPinchPos = HandPointerPos(closestHand); currentDeltaPinchPos = currentPinchPos - prevPinchPos; distanceFromInitPinchPos = currentPinchPos - initPositionWhenPinched; prevPinchPos = currentPinchPos; } if (pinched && moveWithPinch) { if (twoHandedTRS && bothHandsPinched) { // TRS with 2 hands var midpoint = (HandUIManager.pinchLeft.pose.position + HandUIManager.pinchLeft.pose.position) / 2; var currentDistance = Vector3.Distance(HandUIManager.pinchLeft.pose.position, HandUIManager.pinchRight.pose.position); var currentRightToLeft = HandUIManager.pinchLeft.pose.position - HandUIManager.pinchRight.pose.position; currentRightToLeft.y = 0; var angle = Vector3.SignedAngle(currentRightToLeft, onGrabRightToLeft, Vector3.up); if (!reset) { deltaAngle = prevAngle - angle; } else { reset = false; } prevAngle = angle; onGrabMidpointOffset = Quaternion.Euler(0, deltaAngle, 0) * onGrabMidpointOffset; transform.Rotate(deltaAngle * Vector3.up); transform.position = midpoint - onGrabMidpointOffset * currentDistance / onGrabDistanceBetweenHands; transform.localScale = onGrabScale * currentDistance / onGrabDistanceBetweenHands; } else { // move with one hand transform.position = HandPointerPos(closestHand) - onGrabMidpointOffset; } } }