Пример #1
0
    /// <summary>
    /// Releases the object in hand.
    /// </summary>
    private void ReleaseObjectInHand()
    {
        // Only release when the object is in hand.
        if (objectInHand != null)
        {
            // Stop tracking
            Destroy(oIHHandTracker);
            oIHHandTracker = null;

            // Throw if enabled
            if (throwEnable)
            {
                // Get hand velocity from physics engine when not tracked object
                if (!isTrackedObject)
                {
                    // Set object in hand velocity to that of the hand.
                    objectInHand.GetComponent <Rigidbody>().velocity        = throwMultiplier * handRB.velocity;
                    objectInHand.GetComponent <Rigidbody>().angularVelocity = throwMultiplier * handRB.angularVelocity;
                }
                else
                {
                    objectInHand.GetComponent <Rigidbody>().velocity = throwMultiplier * EstiamteHandVelocity();
                }
            }
            // Clear interaction
            isInteractable    = false;
            objectInteraction = null;
            // Start release and cool-off period.
            inDropOff = false;
            releasing = true;
            StartCoroutine(EnableObjectGraspability(2.0f));
        }
    }
Пример #2
0
    /// <summary>
    /// Handles grasping behaviour.
    /// </summary>
    private void HandleGrasp()
    {
        // Check manager type and if requested to interact.
        if (managerType == GraspManagerType.Assisted || (managerType == GraspManagerType.Controller && SteamVR_Input.GetAction <SteamVR_Action_Boolean>("ObjectInteractButton").GetStateDown(SteamVR_Input_Sources.Any)))
        {
            if (objectGraspable == null)
            {
                throw new System.NullReferenceException("There was no object found within grasp.");
            }

            // Attach object to hand with hand Tracking script
            objectInHand   = objectGraspable;
            oIHHandTracker = objectInHand.AddComponent <ObjectGraspHandle>();
            oIHHandTracker.handTransform = attachmentPoint;
            // Check whether the object is interactable and set if so.
            IInteractable interactionScript = objectInHand.GetComponent <IInteractable>();
            if (interactionScript != null)
            {
                isInteractable    = true;
                objectInteraction = interactionScript;
            }
            // clear flag and handle
            inGrasp         = false;
            objectGraspable = null;
        }
    }
Пример #3
0
 // Clear object from hand and return to normal state if quitting application
 private void OnApplicationQuit()
 {
     if (objectInHand != null)
     {
         Destroy(oIHHandTracker);
         oIHHandTracker = null;
         StartCoroutine(EnableObjectGraspability(1.0f));
     }
 }