コード例 #1
0
ファイル: OVRInputModule.cs プロジェクト: DevZhav/The-Forest
        protected override void ProcessDrag(PointerEventData pointerEvent)
        {
            Vector2 position = pointerEvent.position;
            bool    flag     = OVRInputModule.IsPointerMoving(pointerEvent);

            if (flag && pointerEvent.pointerDrag != null && !pointerEvent.dragging && this.ShouldStartDrag(pointerEvent))
            {
                if (pointerEvent.IsVRPointer())
                {
                    pointerEvent.position = this.SwipeAdjustedPosition(position, pointerEvent);
                }
                ExecuteEvents.Execute <IBeginDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler);
                pointerEvent.dragging = true;
            }
            if (pointerEvent.dragging && flag && pointerEvent.pointerDrag != null)
            {
                if (pointerEvent.IsVRPointer())
                {
                    pointerEvent.position = this.SwipeAdjustedPosition(position, pointerEvent);
                }
                if (pointerEvent.pointerPress != pointerEvent.pointerDrag)
                {
                    ExecuteEvents.Execute <IPointerUpHandler>(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
                    pointerEvent.eligibleForClick = false;
                    pointerEvent.pointerPress     = null;
                    pointerEvent.rawPointerPress  = null;
                }
                ExecuteEvents.Execute <IDragHandler>(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler);
            }
        }
コード例 #2
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
            {
#if UNITY_ANDROID && !UNITY_EDITOR  // On android allow swiping to start drag
                if (useSwipeScroll && ((Vector3)pointerEvent.GetSwipeStart() - Input.mousePosition).magnitude > swipeDragThreshold)
                {
                    return(true);
                }
#endif
                // 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)));
            }
        }
コード例 #3
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):
                }
            }
        }
コード例 #4
0
ファイル: OVRInputModule.cs プロジェクト: DGiroud/JavelinVR
 /// <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():
 }
コード例 #5
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());
     }
 }
コード例 #6
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 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);
            }
        }
コード例 #7
0
ファイル: OVRInputModule.cs プロジェクト: DevZhav/The-Forest
        private bool ShouldStartDrag(PointerEventData pointerEvent)
        {
            if (!pointerEvent.useDragThreshold)
            {
                return(true);
            }
            if (!pointerEvent.IsVRPointer())
            {
                return((pointerEvent.pressPosition - pointerEvent.position).sqrMagnitude >= (float)(base.eventSystem.pixelDragThreshold * base.eventSystem.pixelDragThreshold));
            }
            Vector3 position    = pointerEvent.pressEventCamera.transform.position;
            Vector3 normalized  = (pointerEvent.pointerPressRaycast.worldPosition - position).normalized;
            Vector3 normalized2 = (pointerEvent.pointerCurrentRaycast.worldPosition - position).normalized;

            return(Vector3.Dot(normalized, normalized2) < Mathf.Cos(0.0174532924f * this.angleDragThreshold));
        }
コード例 #8
0
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

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

            var ray = eventData.GetRay();

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.RaycastAll(ray, 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);
                }
            }
        }
コード例 #9
0
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            if (this.eventCamera == null)
            {
                return;
            }
            if (!eventData.IsVRPointer())
            {
                return;
            }
            Ray   ray         = eventData.GetRay();
            float maxDistance = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane;

            RaycastHit[] array = Physics.RaycastAll(ray, maxDistance, this.finalEventMask);
            if (array.Length > 1)
            {
                Array.Sort <RaycastHit>(array, (RaycastHit r1, RaycastHit r2) => r1.distance.CompareTo(r2.distance));
            }
            if (array.Length != 0)
            {
                int i   = 0;
                int num = array.Length;
                while (i < num)
                {
                    RaycastResult item = new RaycastResult
                    {
                        gameObject    = array[i].collider.gameObject,
                        module        = this,
                        distance      = array[i].distance,
                        index         = (float)resultAppendList.Count,
                        worldPosition = array[0].point,
                        worldNormal   = array[0].normal
                    };
                    resultAppendList.Add(item);
                    i++;
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

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

            var ray = eventData.GetRay();

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.RaycastAll(ray, 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)
                {
//                    Debug.Log(hits[b].collider.gameObject.name);
                    oLabel = hits[b].collider.gameObject.GetComponent <Labeling>();

                    if (oLabel != null)
                    {
                        oLabel.ShowLabel();
//                        Debug.Log("Show from Raycaster");
                    }

                    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);
                }
            }
            else
            {
                objectLabels = GameObject.FindGameObjectsWithTag("gazeLabels");

                foreach (GameObject label in objectLabels)
                {
                    label.SetActive(false);
                }

/*                for (int i = 0; i < objectLabels.Length; i++)
 *              {
 *                  objectLabels[i].SetActive(false);
 *              }*/
            }
        }
コード例 #11
0
ファイル: OVRInputModule.cs プロジェクト: DevZhav/The-Forest
 private static bool IsPointerMoving(PointerEventData pointerEvent)
 {
     return(pointerEvent.IsVRPointer() || pointerEvent.IsPointerMoving());
 }
コード例 #12
0
ファイル: OVRInputModule.cs プロジェクト: DevZhav/The-Forest
        private void ProcessMousePress(PointerInputModule.MouseButtonEventData data)
        {
            PointerEventData buttonData = data.buttonData;
            GameObject       gameObject = buttonData.pointerCurrentRaycast.gameObject;

            if (data.PressedThisFrame())
            {
                buttonData.eligibleForClick = true;
                buttonData.delta            = Vector2.zero;
                buttonData.dragging         = false;
                buttonData.useDragThreshold = true;
                buttonData.pressPosition    = buttonData.position;
                if (buttonData.IsVRPointer())
                {
                    buttonData.SetSwipeStart(Input.mousePosition);
                }
                buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast;
                base.DeselectIfSelectionChanged(gameObject, buttonData);
                GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy <IPointerDownHandler>(gameObject, buttonData, ExecuteEvents.pointerDownHandler);
                if (gameObject2 == null)
                {
                    gameObject2 = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                }
                float unscaledTime = Time.unscaledTime;
                if (gameObject2 == buttonData.lastPress)
                {
                    float num = unscaledTime - buttonData.clickTime;
                    if (num < 0.3f)
                    {
                        buttonData.clickCount++;
                    }
                    else
                    {
                        buttonData.clickCount = 1;
                    }
                    buttonData.clickTime = unscaledTime;
                }
                else
                {
                    buttonData.clickCount = 1;
                }
                buttonData.pointerPress    = gameObject2;
                buttonData.rawPointerPress = gameObject;
                buttonData.clickTime       = unscaledTime;
                buttonData.pointerDrag     = ExecuteEvents.GetEventHandler <IDragHandler>(gameObject);
                if (buttonData.pointerDrag != null)
                {
                    ExecuteEvents.Execute <IInitializePotentialDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag);
                }
            }
            if (data.ReleasedThisFrame())
            {
                ExecuteEvents.Execute <IPointerUpHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler);
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(gameObject);
                if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick)
                {
                    ExecuteEvents.Execute <IPointerClickHandler>(buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler);
                }
                else if (buttonData.pointerDrag != null)
                {
                    ExecuteEvents.ExecuteHierarchy <IDropHandler>(gameObject, buttonData, ExecuteEvents.dropHandler);
                }
                buttonData.eligibleForClick = false;
                buttonData.pointerPress     = null;
                buttonData.rawPointerPress  = null;
                if (buttonData.pointerDrag != null && buttonData.dragging)
                {
                    ExecuteEvents.Execute <IEndDragHandler>(buttonData.pointerDrag, buttonData, ExecuteEvents.endDragHandler);
                }
                buttonData.dragging    = false;
                buttonData.pointerDrag = null;
                if (gameObject != buttonData.pointerEnter)
                {
                    base.HandlePointerExitAndEnter(buttonData, null);
                    base.HandlePointerExitAndEnter(buttonData, gameObject);
                }
            }
        }