Esempio n. 1
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.IsSyncVRPointer())
            {
                // 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.SyncVRGetSwipeStart() - 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)));
            }
        }
Esempio n. 2
0
        protected Vector2 SwipeAdjustedPosition(Vector2 originalPosition, PointerEventData pointerEvent)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // On android we use the touchpad position (accessed through Input.mousePosition) to modify
            // the effective cursor position for events related to dragging. This allows the user to
            // use the touchpad to drag draggable UI elements
            if (useSwipeScroll)
            {
                Vector2 delta = (Vector2)Input.mousePosition - pointerEvent.SyncVRGetSwipeStart();
                if (InvertSwipeXAxis)
                {
                    delta.x *= -1;
                }
                return(originalPosition + delta * swipeDragScale);
            }
#endif
            // If not Gear VR or swipe scroll isn't enabled just return original position
            return(originalPosition);
        }