Ejemplo n.º 1
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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
 protected virtual GameObject GetFromGrab()
 {
     if (interactGrab != null)
     {
         return(interactGrab.GetGrabbedObject());
     }
     return(null);
 }
Ejemplo n.º 3
0
        protected virtual void DoControllerUse(object sender, ObjectInteractEventArgs e)
        {
            bool isGrabbing = (interactGrab != null && interactGrab.GetGrabbedObject() != null);

            float[] overrideFingerAxis = (isGrabbing ? GetOverrideValues(grabOverrides) : fingerAxis);
            SetAnimatorStateOn("UseState", useOverrides);
            HandleOverrideOn(useOverrides.ignoreAllOverrides, overrideFingerAxis, GetOverridePermissions(useOverrides), GetOverrideValues(useOverrides));
        }
Ejemplo n.º 4
0
        protected virtual float OverrideBeamLength(float currentLength)
        {
            if (!controllerGrabScript || !controllerGrabScript.GetGrabbedObject())
            {
                savedBeamLength = 0f;
            }

            if (controllingPointer && controllingPointer.interactWithObjects && controllingPointer.grabToPointerTip && attachedToInteractorAttachPoint && controllerGrabScript && controllerGrabScript.GetGrabbedObject())
            {
                savedBeamLength = (savedBeamLength == 0f ? currentLength : savedBeamLength);
                return(savedBeamLength);
            }
            return(currentLength);
        }
Ejemplo n.º 5
0
    void RightControllerEvents_TriggerDown(object sender, VRTK.ControllerInteractionEventArgs e)
    {
        if (RightInteractGrab.GetGrabbedObject() != null || // If we already have an object that we have grabbed
            RightInteractTouch.GetTouchedObject() != null)  // .. or if we are touching an interactable object
        {
            return;
        }

        if (RightInteractNearTouch.GetNearTouchedObjects().Count > 0) // If we near interactable objects
        {
            if (ValidateNearObjects())
            {
                return;
            }
        }

        ChangeGameMode(GameMode.DRAW);
    }
Ejemplo n.º 6
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();
                }
            }
        }
Ejemplo n.º 7
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;
        }
 private bool CanGrab(VRTK_InteractGrab grabbingController)
 {
     return (grabbingController && grabbingController.GetGrabbedObject() == null && grabbingController.gameObject.GetComponent<VRTK_ControllerEvents>().grabPressed);
 }