private void Start() { _playerAvatar = GetComponent <PlayerAvatar>(); _leftHandGrabContext = new HandGrabContext { HandType = HandType.Left, HandGameObject = _playerAvatar.AvatarLeftHand, CollisionDetector = _playerAvatar.AvatarLeftHand.GetComponent <PlayerAvatarCollisionDetector>() }; _rightHandGrabContext = new HandGrabContext { HandType = HandType.Right, HandGameObject = _playerAvatar.AvatarRightHand, CollisionDetector = _playerAvatar.AvatarRightHand.GetComponent <PlayerAvatarCollisionDetector>() }; }
private void CheckGripOnController(HandGrabContext context, SteamVR_TrackedController controller) { var grippedNow = controller.gripped; var gripDown = !context.IsGripped && grippedNow; var gripUp = context.IsGripped && !grippedNow; context.IsGripped = grippedNow; if (gripDown) { float minDistance = float.MaxValue; InteractableItem closestItem = null; foreach (var item in context.CollisionDetector.CollisionItems) { var distance = (item.transform.position - controller.transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestItem = item; } } if (closestItem != null) { Debug.Log("Send command to server: PickUpObject, ObjectId=" + closestItem.netId + ", PlayerId=" + _playerAvatar.netId + ", Hand=" + context.HandType); CmdPickUpObject(context.HandType, closestItem.netId); } } if (gripUp) { Debug.Log("Send command to server: DropObject, PlayerId=" + _playerAvatar.netId + ", Hand=" + context.HandType); CmdDropObject(context.HandType); } }