Пример #1
0
 /// <summary>
 /// Called on input release
 /// </summary>
 protected virtual void OnRelease(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoReleaseFlick(pointer);
     }
 }
Пример #2
0
 /// <summary>
 /// Called on input press
 /// </summary>
 protected virtual void OnPress(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoFlickCatch(pointer);
     }
 }
Пример #3
0
 /// <summary>
 /// Called on input press, for MMB panning
 /// </summary>
 protected virtual void OnPress(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoMiddleMousePan(pointer);
     }
 }
Пример #4
0
        /// <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
                Ray prevRay = cameraRig.cachedCamera.ScreenPointToRay(pointer.currentPosition -
                                                                      pointer.flickVelocity);
                Ray currRay = cameraRig.cachedCamera.ScreenPointToRay(pointer.currentPosition);

                Vector3 startPoint = Vector3.zero;
                Vector3 endPoint   = Vector3.zero;
                float   dist;

                if (cameraRig.floorPlane.Raycast(prevRay, out dist))
                {
                    startPoint = prevRay.GetPoint(dist);
                }
                if (cameraRig.floorPlane.Raycast(currRay, out dist))
                {
                    endPoint = currRay.GetPoint(dist);
                }

                // Work out that movement in units per second
                m_FlickDirection = (startPoint - endPoint) / Time.deltaTime;
            }
        }
Пример #5
0
 /// <summary>
 /// Called when we drag
 /// </summary>
 protected virtual void OnDrag(PointerActionInfo pointer)
 {
     if (cameraRig != null)
     {
         DoRightMouseDragPan(pointer);
     }
 }
Пример #6
0
        /// <summary>
        /// Controls the pan with a drag
        /// </summary>
        protected void DoDragPan(PointerActionInfo pointer)
        {
            var touchInfo = pointer as TouchInfo;

            if (touchInfo != null)
            {
                // Work out movement amount by raycasting onto floor plane from delta positions
                // and getting that distance
                Ray currRay = cameraRig.cachedCamera.ScreenPointToRay(touchInfo.currentPosition);

                Vector3 endPoint = Vector3.zero;
                float   dist;
                if (cameraRig.floorPlane.Raycast(currRay, out dist))
                {
                    endPoint = currRay.GetPoint(dist);
                }
                // Pan
                Ray     prevRay    = cameraRig.cachedCamera.ScreenPointToRay(touchInfo.previousPosition);
                Vector3 startPoint = Vector3.zero;

                if (cameraRig.floorPlane.Raycast(prevRay, out dist))
                {
                    startPoint = prevRay.GetPoint(dist);
                }
                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);
            }
        }
Пример #7
0
 /// <summary>
 /// Called when we drag
 /// </summary>
 protected virtual void OnDrag(PointerActionInfo pointer)
 {
     // Drag panning for touch input
     if (cameraRig != null)
     {
         DoDragPan(pointer);
     }
 }
Пример #8
0
        /// <summary>
        /// Controls the pan with a drag
        /// </summary>
        protected void DoDragPan(PointerActionInfo pointer)
        {
            var touchInfo = pointer as TouchInfo;

            if (touchInfo != null)
            {
            }
        }
Пример #9
0
        /// <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)
            {
            }
        }
Пример #10
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;
        }
Пример #11
0
        /// <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;
            }
        }
Пример #12
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))
            {
            }
        }
Пример #13
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);
         }
     }
 }
Пример #14
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;

                var camVector = new Vector3(panVector.x, 0, panVector.y);
                cameraRig.PanCamera(camVector);

                cameraRig.StopTracking();
            }
        }
Пример #15
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))
            {
                // First get floor position of cursor
                Ray ray = cameraRig.cachedCamera.ScreenPointToRay(UnityInput.mousePosition);

                float dist;

                if (cameraRig.floorPlane.Raycast(ray, out dist))
                {
                    Vector3 worldPos = ray.GetPoint(dist);
                    cameraRig.PanTo(worldPos);
                }

                cameraRig.StopTracking();
            }
        }
Пример #16
0
 /// <summary>
 /// Called on input release
 /// </summary>
 protected virtual void OnRelease(PointerActionInfo pointer)
 {
     DoReleaseFlick(pointer);
 }
Пример #17
0
 /// <summary>
 /// Called on input press
 /// </summary>
 protected virtual void OnPress(PointerActionInfo pointer)
 {
     DoFlickCatch(pointer);
 }
Пример #18
0
        /// <summary>
        /// Called when we drag
        /// </summary>
        protected virtual void OnDrag(PointerActionInfo pointer)
        {
            // Drag panning for touch input

            DoDragPan(pointer);
        }
Пример #19
0
 /// <summary>
 /// Called on input press, for MMB panning
 /// </summary>
 protected virtual void OnPress(PointerActionInfo pointer)
 {
     DoMiddleMousePan(pointer);
 }
Пример #20
0
 /// <summary>
 /// Called when we drag
 /// </summary>
 protected virtual void OnDrag(PointerActionInfo pointer)
 {
 }
Пример #21
0
 protected virtual void OnRelease(PointerActionInfo pointer)
 {
 }