/// <summary>
 /// Called on input release
 /// </summary>
 protected virtual void OnRelease(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoReleaseFlick(pointer);
     }
 }
 /// <summary>
 /// Called on input press
 /// </summary>
 protected virtual void OnPress(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoFlickCatch(pointer);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Called when we drag
 /// </summary>
 protected virtual void OnDrag(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoRightMouseDragPan(pointer);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Called on input press, for MMB panning
 /// </summary>
 protected virtual void OnPress(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoMiddleMousePan(pointer);
     }
 }
 /// <summary>
 /// Called when we drag
 /// </summary>
 protected virtual void OnDrag(PointerActionInfo pointer)
 {
     // Drag panning for touch input
     if (cameraRig != null)
     {
         DoDragPan(pointer);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Update a TouchInfo with movement
        /// </summary>
        /// <param name="touch">The Unity touch object</param>
        /// <param name="existingTouch">The object that's tracking Unity's touch</param>
        void UpdateMovingFinger(Touch touch, PointerActionInfo existingTouch)
        {
            float dragDist = touch.deltaPosition.magnitude;

            existingTouch.previousPosition = existingTouch.currentPosition;
            existingTouch.currentPosition  = touch.position;
            existingTouch.delta            = touch.deltaPosition;
            existingTouch.totalMovement   += dragDist;
        }
        /// <summary>
        /// "Catch" flicks on press, to stop the panning momentum
        /// </summary>
        /// <param name="pointer">The press pointer event</param>
        protected void DoFlickCatch(PointerActionInfo pointer)
        {
            var touchInfo = pointer as TouchInfo;

            // Stop flicks on touch
            if (touchInfo != null)
            {
                m_FlickDirection = Vector2.zero;
                cameraRig.StopTracking();
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Update a TouchInfo that might be holding
 /// </summary>
 /// <param name="existingTouch"></param>
 void UpdateHoldingFinger(PointerActionInfo existingTouch)
 {
     if (!existingTouch.isHold &&
         !existingTouch.isDrag &&
         Time.realtimeSinceStartup - existingTouch.startTime >= holdTime)
     {
         existingTouch.isHold = true;
         if (startedHold != null)
         {
             startedHold(existingTouch);
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Pan with middle mouse
        /// </summary>
        /// <param name="pointer">Pointer with press event</param>
        protected void DoMiddleMousePan(PointerActionInfo pointer)
        {
            var mouseInfo = pointer as MouseButtonInfo;

            // Pan to mouse position on MMB
            if ((mouseInfo != null) &&
                (mouseInfo.mouseButtonId == 2))
            {
                Vector3 worldPos = cameraRig.GetRaycastWorldPointOnTargetSurface(UnityInput.mousePosition, Vector3.zero);
                cameraRig.PanTo(worldPos);
                cameraRig.StopTracking();
            }
        }
        /// <summary>
        /// Do flicks, on release only
        /// </summary>
        /// <param name="pointer">The release pointer event</param>
        protected void DoReleaseFlick(PointerActionInfo pointer)
        {
            var touchInfo = pointer as TouchInfo;

            if (touchInfo != null && touchInfo.flickVelocity.sqrMagnitude > Mathf.Epsilon)
            {
                // We have a flick!
                // Work out velocity from motion
                Vector3 startPoint = cameraRig.GetRaycastWorldPointOnTargetSurface(pointer.currentPosition -
                                                                                   pointer.flickVelocity, Vector3.zero);
                Vector3 endPoint = cameraRig.GetRaycastWorldPointOnTargetSurface(pointer.currentPosition, Vector3.zero);

                // Work out that movement in units per second
                m_FlickDirection = (startPoint - endPoint) / Time.deltaTime;
            }
        }
        /// <summary>
        /// Controls the pan with a drag
        /// </summary>
        protected void DoDragPan(PointerActionInfo pointer)
        {
            var touchInfo = pointer as TouchInfo;

            if (touchInfo != null)
            {
                Vector3 endPoint   = cameraRig.GetRaycastWorldPointOnTargetSurface(pointer.currentPosition, Vector3.zero);
                Vector3 startPoint = cameraRig.GetRaycastWorldPointOnTargetSurface(pointer.previousPosition, Vector3.zero);

                Debug.DrawLine(startPoint, endPoint, Color.cyan);
                Vector3 panAmount = startPoint - endPoint;
                // If this is a touch, we divide the pan amount by the number of touches
                if (UnityInput.touchCount > 0)
                {
                    panAmount /= UnityInput.touchCount;
                }

                PanCamera(panAmount);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Pan with right mouse
        /// </summary>
        /// <param name="pointer">The drag pointer event</param>
        protected void DoRightMouseDragPan(PointerActionInfo pointer)
        {
            var mouseInfo = pointer as MouseButtonInfo;

            if ((mouseInfo != null) &&
                (mouseInfo.mouseButtonId == 1))
            {
                // Calculate zoom ratio
                float zoomRatio = GetPanSpeedForZoomLevel();

                Vector2 panVector = (mouseInfo.currentPosition - mouseInfo.startPosition);
                panVector = (panVector * Time.deltaTime * mouseRmbPanSpeed * zoomRatio) / screenPanThreshold;



                cameraRig.PanCamera(panVector);

                cameraRig.StopTracking();
            }
        }