Esempio n. 1
0
    private void PointingTeleport(InputDeviceIDs pointingDevice)
    {
        Vector3 targetPosition;

        switch (pointingDevice)
        {
        case InputDeviceIDs.Head:
            targetPosition = headMovements.focusPoint;
            break;

#if INSTANTVR_ADVANCED
        case InputDeviceIDs.LeftHand:
            targetPosition = leftHandMovements.focusPoint;
            break;

        case InputDeviceIDs.RightHand:
            targetPosition = rightHandMovements.focusPoint;
            break;
#endif
        default:
            targetPosition = ivr.transform.position;
            break;
        }

        Teleport(targetPosition);
    }
Esempio n. 2
0
    public void Start()
    {
        ivr = GetComponent <InstantVR>();
        ivr.SetPlayerHeight(playerHeight);

        Debug.Log("Please press <tab> to calibrate player height.");

        headMovements = ivr.headTarget.GetComponent <HeadMovements>();
#if INSTANTVR_ADVANCED
        leftHandMovements  = ivr.leftHandTarget.GetComponent <IVR_HandMovements>();
        rightHandMovements = ivr.rightHandTarget.GetComponent <IVR_HandMovements>();
#endif

        // get the first player's controller
        controller0 = Controllers.GetController(0);

        // register for button down events
        controller0.left.OnButtonDownEvent  += OnButtonDownLeft;
        controller0.right.OnButtonDownEvent += OnButtonDownRight;

        // register for button up events
        controller0.left.OnButtonUpEvent  += OnButtonUpLeft;
        controller0.right.OnButtonUpEvent += OnButtonUpRight;
#if INSTANTVR_ADVANCED
        if (walkingType == WalkTypes.PointingTeleport)
        {
            pointingDevice = GetPointingDevice();
        }
#endif
    }
Esempio n. 3
0
        private void CastRayFromPointer(InteractionPointer pointer, InputDeviceIDs inputDeviceID)
        {
            pointer.data.Reset();
            pointer.data.inputDevice = inputDeviceID;
            pointer.data.transform   = pointer.pointerTransform;
            if (pointer.pointerTransform == null)
            {
                return;
            }

            CastPhysicsRayFromPointer(pointer);
            CastUIRayFromPointer(pointer);

            pointer.data.scrollDelta = Vector2.zero;
            if (pointer.focusObject != null)
            {
                if (pointer.previousPosition.sqrMagnitude == 0)
                {
                    pointer.data.delta = Vector2.zero;
                }
                else
                {
                    pointer.data.delta = pointer.data.position - pointer.previousPosition;
                }
                pointer.previousPosition = pointer.data.position;

                pointer.touchPosition = pointer.data.pointerCurrentRaycast.worldPosition;
            }
        }
        private void ProcessPointer(InteractionPointer pointer, InputDeviceIDs inputDeviceID)
        {
            CastRayFromPointer(pointer, inputDeviceID);

            pointer.ProcessFocus();
            if (pointer.focusObject != null && pointer.focusTimeToTouch != 0 && Time.time - pointer.focusStart > pointer.focusTimeToTouch)   // we are clicking
            {
                pointer.ProcessClick();
            }

            if (pointer.type == PointerType.Gaze)
            {
                if (pointer.controllerInputSide.GetButton(pointer.controllerButton))   // we are touching
                {
                    pointer.ProcessTouch();
                }
                else
                {
                    pointer.ProcessNoTouch();
                }
            }

            if (pointer.data.pointerCurrentRaycast.gameObject == null)   // no focus
            {
                return;
            }

            //Trigger Enter or Exit Events on the UI Element (like highlighting)
            base.HandlePointerExitAndEnter(pointer.data, pointer.data.pointerCurrentRaycast.gameObject);

            pointer.data.pressPosition       = pointer.data.position;
            pointer.data.pointerPressRaycast = pointer.data.pointerCurrentRaycast;
            pointer.data.pointerPress        = null; //Clear this for setting later
            pointer.data.useDragThreshold    = true;

            if (pointer.type == PointerType.Touch)
            {
                float distance = DistanceTipToTransform(pointer.pointerTransform, pointer.data.pointerCurrentRaycast.gameObject.transform);
                if (distance < 0)   // we are touching
                {
                    pointer.ProcessTouch();
                }
                else
                {
                    pointer.ProcessNoTouch();
                }
            }

            if (pointer.controllerInputSide.GetButton(pointer.controllerButton))   // we are clicking
            {
                pointer.ProcessTouch();
            }
            else
            {
                pointer.ProcessNoTouch();
            }
        }
 public GameObject GetTouchObject(InputDeviceIDs inputDeviceID)
 {
     if (pointers[(int)inputDeviceID].touchedObject != null)
     {
         return(pointers[(int)inputDeviceID].touchedObject);
     }
     else
     {
         return(null);
     }
 }
 public GameObject GetFocusObject(InputDeviceIDs inputDeviceID)
 {
     if (pointers[(int)inputDeviceID].focusObject != null)
     {
         return(pointers[(int)inputDeviceID].focusObject);
     }
     else
     {
         return(null);
     }
 }
        private void CastRayFromPointer(InteractionPointer pointer, InputDeviceIDs inputDeviceID)
        {
            pointer.data.Reset();
            pointer.data.inputDevice = inputDeviceID;

            Vector3 pointingDirection = pointer.pointerTransform.rotation * pointer.localPointingDirection;

            if (pointer.focusingEnabled)
            {
                RaycastHit hit;
                bool       raycastHit = Physics.Raycast(pointer.pointerTransform.position, pointingDirection, out hit);
                if (raycastHit)
                {
                    pointer.focusPosition = hit.point;
                    pointer.focusObject   = hit.transform.gameObject;
                }
                else
                {
                    pointer.focusPosition = pointer.pointerTransform.position + pointingDirection * 10;
                    pointer.focusObject   = null;
                }

                pointer.data.position = Camera.main.WorldToScreenPoint(pointer.focusPosition);
            }
            else
            {
                pointer.focusPosition = pointer.pointerTransform.position;
                pointer.focusObject   = null;

                pointer.data.position = Camera.main.WorldToScreenPoint(pointer.pointerTransform.position);
            }

            pointer.data.scrollDelta = Vector2.zero;
            pointer.data.delta       = pointer.data.position - pointer.previousPosition;
            pointer.previousPosition = pointer.data.position;

            eventSystem.RaycastAll(pointer.data, m_RaycastResultCache);

            pointer.data.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache);
            m_RaycastResultCache.Clear();

            if (pointer.data.pointerCurrentRaycast.gameObject != null)   // we are focusing on a UI element
            {
                pointer.focusObject = pointer.data.pointerCurrentRaycast.gameObject;
                // EventSystem.RaycastAll always casts from main.camera. This is why we need a trick to look like it is casting from the pointerlocation (e.g. finger)
                // The result does not look right in scene view, but does look OK in game view
                Vector3 focusDirection = (pointer.focusPosition - Camera.main.transform.position).normalized;
                pointer.focusPosition = Camera.main.transform.position + focusDirection * pointer.data.pointerCurrentRaycast.distance; // pointer.data.pointerCurrentRaycast.worldPosition == Vector.zero unfortunately
                pointer.data.position = pointer.focusPosition;
            }

            pointer.touchPosition = pointer.data.pointerCurrentRaycast.worldPosition;
        }
Esempio n. 8
0
        private void ProcessPointer(InteractionPointer pointer, InputDeviceIDs inputDeviceID)
        {
            CastRayFromPointer(pointer, inputDeviceID);

            if (pointer.focusingEnabled && pointer.type == PointerType.Point)
            {
                pointer.ProcessFocus();
            }
            if (pointer.focusObject != null && pointer.focusTimeToTouch != 0 && Time.time - pointer.focusStart > pointer.focusTimeToTouch)   // we are clicking
            {
                pointer.ProcessTouch();
                pointer.ProcessNoTouch();
            }
            else if (pointer.clicking)
            {
                pointer.ProcessTouch();
            }

            if (pointer.data.pointerCurrentRaycast.gameObject == null)   // no focus
            {
                return;
            }

            pointer.data.pressPosition       = pointer.data.position;
            pointer.data.pointerPressRaycast = pointer.data.pointerCurrentRaycast;
            pointer.data.pointerPress        = null; //Clear this for setting later
            pointer.data.useDragThreshold    = true;

            if (pointer.type == PointerType.Touch)
            {
                // UI touch without colliders works on the finger tip
                float distance = DistanceTipToTransform(pointer.pointerTransform, pointer.data.pointerCurrentRaycast.gameObject.transform);
                if (distance < 0)   // we are touching
                {
                    pointer.ProcessTouch();
                }
                else if (distance > 0.05F)
                {
                    pointer.ProcessNoTouch();
                }
                else
                {
                    pointer.ProcessFocus();
                }
            }
        }
Esempio n. 9
0
        public GameObject GetTouchObject(InputDeviceIDs inputDeviceID)
        {
            InteractionPointer pointer = pointers[(int)inputDeviceID];

            if (pointer == null)
            {
                return(null);
            }

            if (pointer.touchedObject != null)
            {
                return(pointer.touchedObject);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
 public float GetGazeDuration(InputDeviceIDs inputDeviceID)
 {
     return(Time.time - pointers[(int)inputDeviceID].focusStart);
 }
Esempio n. 11
0
 public Vector3 GetFocusPoint(InputDeviceIDs inputDeviceID)
 {
     return(pointers[(int)inputDeviceID].focusPosition);
 }
Esempio n. 12
0
 public void ProcessPointer(InputDeviceIDs inputDeviceID)
 {
     ProcessPointer(pointers[(int)inputDeviceID], inputDeviceID);
 }
Esempio n. 13
0
 public Vector3 GetTouchPoint(InputDeviceIDs inputDeviceID)
 {
     return(pointers[(int)inputDeviceID].touchPosition);
 }