public void SetHandDiffs(bool _leftHand, Vector3 handPosition) { HandGrabPose closestHandPose = null; attachTransform = this.gameObject.transform; float lastDist = float.MaxValue; //get closest distance from hand foreach (HandGrabPose item in handGrabPoses.FindAll(p => p.leftHand == _leftHand)) { Vector3 positionCompair = positionOfParent ? item.gameObject.transform.parent.position : item.gameObject.transform.position; item.SetDebugHand(false); float dist = Vector3.Distance(handPosition, positionCompair); if (dist < lastDist) { closestHandPose = item; lastDist = dist; } } if (closestHandPose != null) { attachTransform = closestHandPose.GetAttachPoint(); grabbingType = closestHandPose.grabbingType; animateFrame = closestHandPose.animateFrame; closestHandPose.SetDebugHand(true); } else { attachTransform = this.gameObject.transform; grabbingType = grabbingType != GrabbingType.SimpleFingerTip ? GrabbingType.None : grabbingType; animateFrame = 0f; } }
public void SetVariables(GrabbingType grabbingType, float animationValue) { grabType = grabbingType; animationFrame = animationValue; anim.Update(Time.deltaTime); GetGraspPoints(); }
private void OnSelectedEnter(XRBaseInteractable xRBaseInteractor) { if (xRBaseInteractor.GetType() == typeof(XRGrabInteractionCustom)) { grabType = (xRBaseInteractor as XRGrabInteractionCustom).grabbingType; animateGrabFrame = (xRBaseInteractor as XRGrabInteractionCustom).animateFrame; (xRBaseInteractor as XRGrabInteractionCustom).SetHandDiffs(isLeftHand); if ((xRBaseInteractor as XRGrabInteractionCustom).debug) { (xRBaseInteractor as XRGrabInteractionCustom).SetDebugHand(isLeftHand); } } else if (xRBaseInteractor.GetType() == typeof(XRGrabInteractableManyPosesCustom)) { //todo: get the collision position Vector3 handPos = this.transform.position; XRGrabInteractableManyPosesCustom grabInt = (xRBaseInteractor as XRGrabInteractableManyPosesCustom); grabInt.SetHandDiffs(isLeftHand, handPos); grabType = grabInt.grabbingType; animateGrabFrame = grabInt.animateFrame; if (grabType == GrabbingType.SimpleFingerTip && interactable != null) { //change attach to finger attach position interactable.UpdateAttachTransform(interactable.GetFingertipAttach()); } } else { XRSimpleGrabPresets xRSimpleGrab = xRBaseInteractor.gameObject.GetComponent <XRSimpleGrabPresets>(); if (xRSimpleGrab != null) { grabType = xRSimpleGrab.grabbingType; animateGrabFrame = xRSimpleGrab.animateFrame; } else { grabType = GrabbingType.None; } animateGrabFrame = 0f; } }