//------------------------------------------------- protected virtual void OnHandHoverBegin(IF_VR_Steam_Hand hand) { bool showHint = false; // "Catch" the throwable by holding down the interaction button instead of pressing it. // Only do this if the throwable is moving faster than the prescribed threshold speed, // and if it isn't attached to another hand if (!attached && catchingSpeedThreshold != -1) { float catchingThreshold = catchingSpeedThreshold * SteamVR_Utils.GetLossyScale(IF_VR_Steam_Player.instance.trackingOriginTransform); IF_VR_Steam_GrabTypes bestGrabType = hand.GetBestGrabbingType(); if (bestGrabType != IF_VR_Steam_GrabTypes.None) { if (rigidbody.velocity.magnitude >= catchingThreshold) { hand.AttachObject(gameObject, bestGrabType, attachmentFlags); showHint = false; } } } if (showHint) { hand.ShowGrabHint(); } }
//------------------------------------------------- protected virtual void HandHoverUpdate(IF_VR_Steam_Hand hand) { IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting(); if (startingGrabType != IF_VR_Steam_GrabTypes.None) { hand.AttachObject(gameObject, startingGrabType, attachmentFlags, attachmentOffset); hand.HideGrabHint(); } }
protected override void HandHoverUpdate(IF_VR_Steam_Hand hand) { IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting(); if (startingGrabType != IF_VR_Steam_GrabTypes.None) { if (startingGrabType == IF_VR_Steam_GrabTypes.Pinch) { hand.AttachObject(gameObject, startingGrabType, attachmentFlags, pinchOffset); } else if (startingGrabType == IF_VR_Steam_GrabTypes.Grip) { hand.AttachObject(gameObject, startingGrabType, attachmentFlags, gripOffset); } else { hand.AttachObject(gameObject, startingGrabType, attachmentFlags, attachmentOffset); } hand.HideGrabHint(); } }
protected virtual void HandHoverUpdate(IF_VR_Steam_Hand hand) { IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting(); if (interactable.attachedToHand == null && startingGrabType != IF_VR_Steam_GrabTypes.None) { initialMappingOffset = linearMapping.value - CalculateLinearMapping(hand.transform); sampleCount = 0; mappingChangeRate = 0.0f; hand.AttachObject(gameObject, startingGrabType, attachmentFlags); } }
//------------------------------------------------- private void PhysicsAttach( IF_VR_Steam_Hand hand, IF_VR_Steam_GrabTypes startingGrabType ) { PhysicsDetach( hand ); Rigidbody holdingBody = null; Vector3 holdingPoint = Vector3.zero; // The hand should grab onto the nearest rigid body float closestDistance = float.MaxValue; for ( int i = 0; i < rigidBodies.Count; i++ ) { float distance = Vector3.Distance( rigidBodies[i].worldCenterOfMass, hand.transform.position ); if ( distance < closestDistance ) { holdingBody = rigidBodies[i]; closestDistance = distance; } } // Couldn't grab onto a body if ( holdingBody == null ) return; // Create a fixed joint from the hand to the holding body if ( attachMode == AttachMode.FixedJoint ) { Rigidbody handRigidbody = IF_VR_Steam_Util.FindOrAddComponent<Rigidbody>( hand.gameObject ); handRigidbody.isKinematic = true; FixedJoint handJoint = hand.gameObject.AddComponent<FixedJoint>(); handJoint.connectedBody = holdingBody; } // Don't let the hand interact with other things while it's holding us hand.HoverLock( null ); // Affix this point Vector3 offset = hand.transform.position - holdingBody.worldCenterOfMass; offset = Mathf.Min( offset.magnitude, 1.0f ) * offset.normalized; holdingPoint = holdingBody.transform.InverseTransformPoint( holdingBody.worldCenterOfMass + offset ); hand.AttachObject( this.gameObject, startingGrabType, attachmentFlags ); // Update holding list holdingHands.Add( hand ); holdingBodies.Add( holdingBody ); holdingPoints.Add( holdingPoint ); }
//------------------------------------------------- public void SpawnAndAttach(IF_VR_Steam_Hand passedInhand) { IF_VR_Steam_Hand handToUse = passedInhand; if (passedInhand == null) { handToUse = hand; } if (handToUse == null) { return; } GameObject prefabObject = Instantiate(prefab) as GameObject; handToUse.AttachObject(prefabObject, IF_VR_Steam_GrabTypes.Scripted); }
//------------------------------------------------- void Update() { if (itemPrefab != null) { if (hand.isActive && hand.isPoseValid) { GameObject objectToAttach = GameObject.Instantiate(itemPrefab); objectToAttach.SetActive(true); hand.AttachObject(objectToAttach, IF_VR_Steam_GrabTypes.Scripted); hand.TriggerHapticPulse(800); Destroy(gameObject); // If the player's scale has been changed the object to attach will be the wrong size. // To fix this we change the object's scale back to its original, pre-attach scale. objectToAttach.transform.localScale = itemPrefab.transform.localScale; } } }
//------------------------------------------------- private void SpawnAndAttachObject(IF_VR_Steam_Hand hand, IF_VR_Steam_GrabTypes grabType) { if (hand.otherHand != null) { //If the other hand has this item package, take it back from the other hand IF_VR_Steam_ItemPackage otherHandItemPackage = GetAttachedItemPackage(hand.otherHand); if (otherHandItemPackage == itemPackage) { TakeBackItem(hand.otherHand); } } if (showTriggerHint) { hand.HideGrabHint(); } if (itemPackage.otherHandItemPrefab != null) { if (hand.otherHand.hoverLocked) { Debug.Log("<b>[SteamVR Interaction]</b> Not attaching objects because other hand is hoverlocked and we can't deliver both items."); return; } } // if we're trying to spawn a one-handed item, remove one and two-handed items from this hand and two-handed items from both hands if (itemPackage.packageType == IF_VR_Steam_ItemPackage.ItemPackageType.OneHanded) { RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.OneHanded, hand); RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.TwoHanded, hand); RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.TwoHanded, hand.otherHand); } // if we're trying to spawn a two-handed item, remove one and two-handed items from both hands if (itemPackage.packageType == IF_VR_Steam_ItemPackage.ItemPackageType.TwoHanded) { RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.OneHanded, hand); RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.OneHanded, hand.otherHand); RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.TwoHanded, hand); RemoveMatchingItemTypesFromHand(IF_VR_Steam_ItemPackage.ItemPackageType.TwoHanded, hand.otherHand); } spawnedItem = GameObject.Instantiate(itemPackage.itemPrefab); spawnedItem.SetActive(true); hand.AttachObject(spawnedItem, grabType, attachmentFlags); if ((itemPackage.otherHandItemPrefab != null) && (hand.otherHand.isActive)) { GameObject otherHandObjectToAttach = GameObject.Instantiate(itemPackage.otherHandItemPrefab); otherHandObjectToAttach.SetActive(true); hand.otherHand.AttachObject(otherHandObjectToAttach, grabType, attachmentFlags); } itemIsSpawned = true; justPickedUpItem = true; if (takeBackItem) { useFadedPreview = true; pickupEvent.Invoke(); CreatePreviewObject(); } }