예제 #1
0
    // overrides BaseRaycaster
    public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
    {
        if (eventData.IsVRPointer() == false || pointer.interactable == false)
        {
            return;
        }

        var   ray  = pointer.GetWorldRay();
        float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;
        var   hits = Physics.RaycastAll(ray, dist, finalEventMask);

        if (hits.Length > 0)
        {
            if (hits.Length > 1)
            {
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
            }

            for (int i = 0; i < hits.Length; i++)
            {
                var result = new RaycastResult {
                    gameObject    = hits[i].collider.gameObject,
                    module        = this,
                    distance      = hits[i].distance,
                    index         = resultAppendList.Count,
                    worldPosition = hits[0].point,
                    worldNormal   = hits[0].normal
                };
                resultAppendList.Add(result);
            }
        }
    }
예제 #2
0
 /// <summary>
 /// Performs a raycast using eventData.worldSpaceRay
 /// </summary>
 /// <param name="eventData"></param>
 /// <param name="resultAppendList"></param>
 public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
 {
     if (eventData.IsVRPointer())
     {
         Raycast(eventData, resultAppendList, eventData.GetRay(), true):
     }
 }
예제 #3
0
 public void OnPointerExit(PointerEventData e)
 {
     if (e.IsVRPointer())
     {
         OVRInputModule inputModule = EventSystem.current.currentInputModule as OVRInputModule;
         inputModule.activeGraphicRaycaster = null;
     }
 }
예제 #4
0
 public void OnPointerEnter(PointerEventData e)
 {
     if (e.IsVRPointer())
     {
         OVRInputModule ovrinputModule = EventSystem.current.currentInputModule as OVRInputModule;
         ovrinputModule.activeGraphicRaycaster = this;
     }
 }
예제 #5
0
 public void OnPointerEnter(PointerEventData e)
 {
     if (e.IsVRPointer())
     {
         // Gaze has entered this canvas. We'll make it the active one so that canvas-mouse pointer can be used.
         OVRInputModule inputModule = EventSystem.current.currentInputModule as OVRInputModule;
         inputModule.activeGraphicRaycaster = this;
     }
 }
예제 #6
0
 /// <summary>
 /// The purpose of this function is to allow us to switch between using the standard IsPointerMoving
 /// method for mouse driven pointers, but to always return true when it's a ray based pointer.
 /// All real-world ray-based input devices are always moving so for simplicity we just return true
 /// for them.
 ///
 /// If PointerEventData.IsPointerMoving was virtual we could just override that in
 /// OVRRayPointerEventData.
 /// </summary>
 /// <param name="pointerEvent"></param>
 /// <returns></returns>
 static bool IsPointerMoving(PointerEventData pointerEvent)
 {
     if (pointerEvent.IsVRPointer())
     {
         return(true);
     }
     else
     {
         return(pointerEvent.IsPointerMoving());
     }
 }
예제 #7
0
    /// <summary>
    /// Exactly the same as the code from PointerInputModule, except that we call our own
    /// IsPointerMoving.
    ///
    /// This would also not be necessary if PointerEventData.IsPointerMoving was virtual
    /// </summary>
    /// <param name="pointerEvent"></param>
    protected override void ProcessDrag(PointerEventData pointerEvent)
    {
        Vector2 originalPosition = pointerEvent.position;
        bool    moving           = IsPointerMoving(pointerEvent);

        if (moving && pointerEvent.pointerDrag != null &&
            !pointerEvent.dragging &&
            ShouldStartDrag(pointerEvent))
        {
            if (pointerEvent.IsVRPointer())
            {
                //adjust the position used based on swiping action. Allowing the user to
                //drag items by swiping on the GearVR touchpad
                pointerEvent.position = SwipeAdjustedPosition(originalPosition, pointerEvent);
            }
            ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler);
            pointerEvent.dragging = true;
        }

        // Drag notification
        if (pointerEvent.dragging && moving && pointerEvent.pointerDrag != null)
        {
            if (pointerEvent.IsVRPointer())
            {
                pointerEvent.position = SwipeAdjustedPosition(originalPosition, pointerEvent);
            }
            // Before doing drag we should cancel any pointer down state
            // And clear selection!
            if (pointerEvent.pointerPress != pointerEvent.pointerDrag)
            {
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;
            }
            ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler);
        }
    }
예제 #8
0
    public void Raycast(AirXRPointer pointer, PointerEventData eventData, List <RaycastResult> resultAppendList)
    {
        if (eventData.IsVRPointer() == false)
        {
            base.Raycast(eventData, resultAppendList);
            return;
        }

        if (pointer.interactable)
        {
            raycast(eventData, resultAppendList, eventData.GetRay(), true);
        }
    }
 public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
 {
     if (eventData.IsVRPointer())
     {
         if (_pointer.interactable)
         {
             raycast(eventData, resultAppendList, eventData.GetRay(), true);
         }
     }
     else
     {
         base.Raycast(eventData, resultAppendList);
     }
 }
예제 #10
0
        /// <summary>
        ///  Perform a Spherecast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        /// <param name="radius">Radius of the sphere</param>
        public void Spherecast(PointerEventData eventData, List <RaycastResult> resultAppendList, float radius)
        {
            if (eventCamera == null)
            {
                return;
            }

            if (!eventData.IsVRPointer())
            {
                return;
            }

            var ray = eventData.GetRay();

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.SphereCastAll(ray, radius, dist, finalEventMask);

            if (hits.Length > 1)
            {
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
            }

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject    = hits[b].collider.gameObject,
                        module        = this,
                        distance      = hits[b].distance,
                        index         = resultAppendList.Count,
                        worldPosition = hits[0].point,
                        worldNormal   = hits[0].normal,
                    };
                    resultAppendList.Add(result);
                }
            }
        }
예제 #11
0
    /// <summary>
    /// New version of ShouldStartDrag implemented first in PointerInputModule. This version differs in that
    /// for ray based pointers it makes a decision about whether a drag should start based on the angular change
    /// the pointer has made so far, as seen from the camera. This also works when the world space ray is
    /// translated rather than rotated, since the beginning and end of the movement are considered as angle from
    /// the same point.
    /// </summary>
    private bool ShouldStartDrag(PointerEventData pointerEvent)
    {
        if (!pointerEvent.useDragThreshold)
        {
            return(true);
        }

        if (!pointerEvent.IsVRPointer())
        {
            // Same as original behaviour for canvas based pointers
            return((pointerEvent.pressPosition - pointerEvent.position).sqrMagnitude >= eventSystem.pixelDragThreshold * eventSystem.pixelDragThreshold);
        }
        else
        {
            // When it's not a screen space pointer we have to look at the angle it moved rather than the pixels distance
            // For gaze based pointing screen-space distance moved will always be near 0
            Vector3 cameraPos  = pointerEvent.pressEventCamera.transform.position;
            Vector3 pressDir   = (pointerEvent.pointerPressRaycast.worldPosition - cameraPos).normalized;
            Vector3 currentDir = (pointerEvent.pointerCurrentRaycast.worldPosition - cameraPos).normalized;
            return(Vector3.Dot(pressDir, currentDir) < Mathf.Cos(Mathf.Deg2Rad * (angleDragThreshold)));
        }
    }