Пример #1
0
        private IEnumerator Start()
        {
            controller = GetComponent <VRTK_InteractGrab>();
            if (!controller)
            {
                Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script.");
                yield break;
            }

            if (!objectToGrab)
            {
                Debug.LogError("You have to assign an object that should be grabbed.");
                yield break;
            }

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

            VRTK_InteractableObject grabbableObject = objectToGrab;

            if (cloneGrabbedObject)
            {
                grabbableObject = Instantiate(objectToGrab);
            }
            controller.GetComponent <VRTK_InteractTouch>().ForceStopTouching();
            controller.GetComponent <VRTK_InteractTouch>().ForceTouch(grabbableObject.gameObject);
            controller.AttemptGrab();
        }
Пример #2
0
        protected virtual void TryPickup(bool rightHand)
        {
            Ray        screenRay = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            RaycastHit hit;

            if (Physics.Raycast(screenRay, out hit))
            {
                VRTK_InteractableObject io = hit.collider.gameObject.GetComponent <VRTK_InteractableObject>();
                if (io != null)
                {
                    GameObject hand;
                    if (rightHand)
                    {
                        hand = VRTK_DeviceFinder.GetControllerRightHand();
                    }
                    else
                    {
                        hand = VRTK_DeviceFinder.GetControllerLeftHand();
                    }
                    VRTK_InteractGrab grab = hand.GetComponent <VRTK_InteractGrab>();
                    if (grab.GetGrabbedObject() == null)
                    {
                        hand.GetComponent <VRTK_InteractTouch>().ForceTouch(hit.collider.gameObject);
                        grab.AttemptGrab();
                    }
                }
            }
        }
Пример #3
0
        private IEnumerator Start()
        {
            controller = GetComponent <VRTK_InteractGrab>();

            if (!controller)
            {
                Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script.");
            }

            if (!objectToGrab || !objectToGrab.GetComponent <VRTK_InteractableObject>())
            {
                Debug.LogError("The objectToGrab Game Object must have the VRTK_InteractableObject script applied to it.");
            }

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

            var grabbableObject = objectToGrab;

            if (cloneGrabbedObject)
            {
                grabbableObject = Instantiate(objectToGrab);
            }
            controller.GetComponent <VRTK_InteractTouch>().ForceTouch(grabbableObject);
            controller.AttemptGrab();
        }
Пример #4
0
 protected virtual void CheckGrab(GameObject interactingObject)
 {
     if (grabOnTouchWhen != AutoInteractions.Never && regrabTimer < Time.time)
     {
         VRTK_InteractGrab interactGrabScript = interactingObject.GetComponentInChildren <VRTK_InteractGrab>();
         if (interactGrabScript != null && (grabOnTouchWhen == AutoInteractions.NoButtonHeld || (grabOnTouchWhen == AutoInteractions.ButtonHeld && interactGrabScript.IsGrabButtonPressed())))
         {
             interactGrabScript.AttemptGrab();
         }
     }
 }
Пример #5
0
 // Token: 0x060016C5 RID: 5829 RVA: 0x0007ACAC File Offset: 0x00078EAC
 protected virtual void CheckGrab(GameObject interactingObject)
 {
     if (this.grabOnTouchWhen != VRTK_ObjectTouchAutoInteract.AutoInteractions.Never && this.regrabTimer < Time.time)
     {
         VRTK_InteractGrab component = interactingObject.GetComponent <VRTK_InteractGrab>();
         if (component != null && (this.grabOnTouchWhen == VRTK_ObjectTouchAutoInteract.AutoInteractions.NoButtonHeld || (this.grabOnTouchWhen == VRTK_ObjectTouchAutoInteract.AutoInteractions.ButtonHeld && component.IsGrabButtonPressed())))
         {
             component.AttemptGrab();
         }
     }
 }
Пример #6
0
        private void InitAutoGrab()
        {
            var grabbableObject = objectToGrab;

            if (cloneGrabbedObject)
            {
                grabbableObject = Instantiate(objectToGrab);
            }
            controller.GetComponent <VRTK_InteractTouch>().ForceTouch(grabbableObject);
            controller.AttemptGrab();
        }
Пример #7
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();
         }
     }
 }
        private IEnumerator AutoGrab()
        {
            controller = GetComponent <VRTK_InteractGrab>();
            if (!controller)
            {
                Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script.");
                yield break;
            }

            if (!objectToGrab)
            {
                Debug.LogError("You have to assign an object that should be grabbed.");
                yield break;
            }

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

            grabbableObject = objectToGrab;
            if (cloneGrabbedObject)
            {
                if (previousClonedObject == null)
                {
                    grabbableObject      = Instantiate(objectToGrab);
                    previousClonedObject = grabbableObject;
                }
                else
                {
                    grabbableObject = previousClonedObject;
                }
            }

            if (grabbableObject.isGrabbable && !grabbableObject.IsGrabbed())
            {
                if (grabbableObject.AttachIsKinematicObject())
                {
                    grabbableObject.ToggleKinematic(true);
                }

                grabbableObject.transform.position = transform.position;
                controller.GetComponent <VRTK_InteractTouch>().ForceStopTouching();
                controller.GetComponent <VRTK_InteractTouch>().ForceTouch(grabbableObject.gameObject);
                controller.AttemptGrab();
            }
        }
        private IEnumerator AutoGrab()
        {
            controller = GetComponent<VRTK_InteractGrab>();
            if (!controller)
            {
                Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script.");
                yield break;
            }

            if (!objectToGrab)
            {
                Debug.LogError("You have to assign an object that should be grabbed.");
                yield break;
            }

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

            grabbableObject = objectToGrab;
            if (cloneGrabbedObject)
            {
                if (previousClonedObject == null)
                {
                    grabbableObject = Instantiate(objectToGrab);
                    previousClonedObject = grabbableObject;
                }
                else
                {
                    grabbableObject = previousClonedObject;
                }
            }

            if (grabbableObject.isGrabbable && !grabbableObject.IsGrabbed())
            {
                if (grabbableObject.AttachIsKinematicObject())
                {
                    grabbableObject.ToggleKinematic(true);
                }

                grabbableObject.transform.position = transform.position;
                controller.GetComponent<VRTK_InteractTouch>().ForceStopTouching();
                controller.GetComponent<VRTK_InteractTouch>().ForceTouch(grabbableObject.gameObject);
                controller.AttemptGrab();
            }
        }
Пример #10
0
        // Token: 0x060012CB RID: 4811 RVA: 0x00069C64 File Offset: 0x00067E64
        private void TryPickup(bool rightHand)
        {
            RaycastHit raycastHit;

            if (Physics.Raycast(Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)), out raycastHit) && raycastHit.collider.gameObject.GetComponent <VRTK_InteractableObject>())
            {
                GameObject gameObject;
                if (rightHand)
                {
                    gameObject = VRTK_DeviceFinder.GetControllerRightHand(false);
                }
                else
                {
                    gameObject = VRTK_DeviceFinder.GetControllerLeftHand(false);
                }
                VRTK_InteractGrab component = gameObject.GetComponent <VRTK_InteractGrab>();
                if (component.GetGrabbedObject() == null)
                {
                    gameObject.GetComponent <VRTK_InteractTouch>().ForceTouch(raycastHit.collider.gameObject);
                    component.AttemptGrab();
                }
            }
        }
Пример #11
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;
        }