protected virtual void RegrabUndroppableObject()
 {
     if (undroppableGrabbedObject != null && !undroppableGrabbedObject.GetComponent <VRTK_InteractableObject>().IsGrabbed())
     {
         undroppableGrabbedObject.SetActive(true);
         interactTouch.ForceTouch(undroppableGrabbedObject);
         AttemptGrab();
     }
     else
     {
         undroppableGrabbedObject = null;
     }
 }
Пример #2
0
 protected virtual void AttemptSecondaryGrab(VRTK_InteractableObject grabbableObject)
 {
     if (attemptSecondaryGrab)
     {
         SDK_BaseController.ControllerHand currentHand = VRTK_DeviceFinder.GetControllerHand(interactTouch.gameObject);
         VRTK_ControllerReference          oppositeControllerReference = VRTK_ControllerReference.GetControllerReference(VRTK_DeviceFinder.GetOppositeHand(currentHand));
         if (VRTK_ControllerReference.IsValid(oppositeControllerReference))
         {
             secondaryInteractTouch = (secondaryInteractTouch == null ? oppositeControllerReference.scriptAlias.GetComponentInChildren <VRTK_InteractTouch>() : secondaryInteractTouch);
             secondaryInteractGrab  = (secondaryInteractGrab == null ? oppositeControllerReference.scriptAlias.GetComponentInChildren <VRTK_InteractGrab>() : secondaryInteractGrab);
             secondaryInteractTouch.ForceStopTouching();
             secondaryInteractTouch.ForceTouch(grabbableObject.gameObject);
             secondaryInteractGrab.AttemptGrab();
         }
     }
 }
 protected override void RegrabUndroppableObject()
 {
     if (undroppableGrabbedObject != null)
     {
         VRTK_InteractableObject undroppableGrabbedObjectScript = undroppableGrabbedObject.GetComponent <VRTK_InteractableObject>();
         if (interactTouch != null && undroppableGrabbedObjectScript != null && !undroppableGrabbedObjectScript.IsGrabbed())
         {
             undroppableGrabbedObject.SetActive(true);
             interactTouch.ForceTouch(undroppableGrabbedObject);
             AttemptGrab();
         }
     }
     else
     {
         undroppableGrabbedObject = null;
     }
 }
Пример #4
0
        private void OnEnable()
        {
            if (GetComponent <VRTK_ControllerEvents>() == null)
            {
                Debug.LogError("VRTK_InteractGrab is required to be attached to a Controller that has the VRTK_ControllerEvents script attached to it");
                return;
            }

            if (undroppableGrabbedObject && !undroppableGrabbedObject.GetComponent <VRTK_InteractableObject>().IsGrabbed())
            {
                undroppableGrabbedObject.SetActive(true);
                interactTouch.ForceTouch(undroppableGrabbedObject);
                AttemptGrab();
            }
            else
            {
                undroppableGrabbedObject = null;
            }

            GetComponent <VRTK_ControllerEvents>().AliasGrabOn  += new ControllerInteractionEventHandler(DoGrabObject);
            GetComponent <VRTK_ControllerEvents>().AliasGrabOff += new ControllerInteractionEventHandler(DoReleaseObject);

            SetControllerAttachPoint();
        }
Пример #5
0
        protected virtual IEnumerator AutoGrab()
        {
            yield return(new WaitForEndOfFrame());

            interactTouch = (interactTouch != null ? interactTouch : GetComponentInParent <VRTK_InteractTouch>());
            interactGrab  = (interactGrab != null ? interactGrab : GetComponentInParent <VRTK_InteractGrab>());

            if (interactTouch == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, "VRTK_ObjectAutoGrab", "VRTK_InteractTouch", "interactTouch", "the same or parent"));
            }

            if (interactGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, "VRTK_ObjectAutoGrab", "VRTK_InteractGrab", "interactGrab", "the same or parent"));
            }

            if (objectToGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.NOT_DEFINED, "objectToGrab"));
                yield break;
            }

            while (interactGrab.controllerAttachPoint == null)
            {
                yield return(true);
            }

            bool grabbableObjectDisableState = objectToGrab.disableWhenIdle;

            if (objectIsPrefab)
            {
                objectToGrab.disableWhenIdle = false;
            }

            VRTK_InteractableObject grabbableObject = objectToGrab;

            if (alwaysCloneOnEnable)
            {
                ClearPreviousClone();
            }

            if (!interactGrab.GetGrabbedObject())
            {
                if (cloneGrabbedObject)
                {
                    if (previousClonedObject == null)
                    {
                        grabbableObject      = Instantiate(objectToGrab);
                        previousClonedObject = grabbableObject;
                    }
                    else
                    {
                        grabbableObject = previousClonedObject;
                    }
                }

                if (grabbableObject.isGrabbable && !grabbableObject.IsGrabbed())
                {
                    grabbableObject.transform.position = transform.position;
                    interactTouch.ForceStopTouching();
                    interactTouch.ForceTouch(grabbableObject.gameObject);
                    interactGrab.AttemptGrab();
                }
            }
            objectToGrab.disableWhenIdle    = grabbableObjectDisableState;
            grabbableObject.disableWhenIdle = grabbableObjectDisableState;
        }