Esempio n. 1
0
        //-------------------------------------------------
        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();
            }
        }
        //-------------------------------------------------
        private void HandHoverUpdate(IF_VR_Steam_Hand hand)
        {
            if (takeBackItem && requireReleaseActionToReturn)
            {
                if (hand.isActive)
                {
                    IF_VR_Steam_ItemPackage currentAttachedItemPackage = GetAttachedItemPackage(hand);
                    if (currentAttachedItemPackage == itemPackage && hand.IsGrabEnding(currentAttachedItemPackage.gameObject))
                    {
                        TakeBackItem(hand);
                        return;                         // So that we don't pick up an IF_VR_Steam_ItemPackage the same frame that we return it
                    }
                }
            }

            if (requireGrabActionToTake)
            {
                IF_VR_Steam_GrabTypes startingGrab = hand.GetGrabStarting();

                if (startingGrab != IF_VR_Steam_GrabTypes.None)
                {
                    SpawnAndAttachObject(hand, IF_VR_Steam_GrabTypes.Scripted);
                }
            }
        }
        //-------------------------------------------------
        private void HandHoverUpdate( IF_VR_Steam_Hand hand )
        {
            IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting();

            if (startingGrabType != IF_VR_Steam_GrabTypes.None)
            {
                PhysicsAttach( hand, startingGrabType );
            }
        }
Esempio n. 4
0
        //-------------------------------------------------
        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 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 static IF_VR_GrabType ConvertTo(this IF_VR_Steam_GrabTypes type)
 {
     if (type == IF_VR_Steam_GrabTypes.Grip)
     {
         return(IF_VR_GrabType.Grip);
     }
     else if (type == IF_VR_Steam_GrabTypes.Pinch)
     {
         return(IF_VR_GrabType.Pinch);
     }
     else if (type == IF_VR_Steam_GrabTypes.Scripted)
     {
         return(IF_VR_GrabType.Scripted);
     }
     return(IF_VR_GrabType.None);
 }
        //-------------------------------------------------
        private void HandHoverUpdate(IF_VR_Steam_Hand hand)
        {
            IF_VR_Steam_GrabTypes startingGrabType = hand.GetGrabStarting();
            bool isGrabEnding = hand.IsGrabbingWithType(grabbedWithType) == false;

            if (grabbedWithType == IF_VR_Steam_GrabTypes.None && startingGrabType != IF_VR_Steam_GrabTypes.None)
            {
                grabbedWithType = startingGrabType;
                // Trigger was just pressed
                lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform);

                if (hoverLock)
                {
                    hand.HoverLock(interactable);
                    handHoverLocked = hand;
                }

                driving = true;

                ComputeAngle(hand);
                UpdateAll();

                hand.HideGrabHint();
            }
            else if (grabbedWithType != IF_VR_Steam_GrabTypes.None && isGrabEnding)
            {
                // Trigger was just released
                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }

                driving         = false;
                grabbedWithType = IF_VR_Steam_GrabTypes.None;
            }

            if (driving && isGrabEnding == false && hand.hoveringInteractable == this.interactable)
            {
                ComputeAngle(hand);
                UpdateAll();
            }
        }
        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();
            }
        }
        //-------------------------------------------------
        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();
            }
        }