Beispiel #1
0
        public static bool TryGetWorldDelta(List <NewLeanFinger> fingers, float distance, ref Vector3 delta, Camera camera = null)
        {
            if (NewLeanTouch.GetCamera(ref camera) == true)
            {
                if (fingers != null)
                {
                    var total = Vector3.zero;
                    var count = 0;

                    for (var i = fingers.Count - 1; i >= 0; i--)
                    {
                        var finger = fingers[i];

                        if (finger != null)
                        {
                            total += finger.GetWorldDelta(distance, camera);
                            count += 1;
                        }
                    }

                    if (count > 0)
                    {
                        delta = total / count; return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        public Vector3 GetWorldDelta(float lastDistance, float distance, Camera camera = null)
        {
            if (NewLeanTouch.GetCamera(ref camera) == true)
            {
                return(GetWorldPosition(distance, camera) - GetLastWorldPosition(lastDistance, camera));
            }

            return(default(Vector3));
        }
Beispiel #3
0
        // This will return the ray of the finger's start position
        public Ray GetStartRay(Camera camera = null)
        {
            if (NewLeanTouch.GetCamera(ref camera) == true)
            {
                return(camera.ScreenPointToRay(StartScreenPosition));
            }

            return(default(Ray));
        }
Beispiel #4
0
        // This will return the world position of this finger based on the distance from the camera
        public Vector3 GetWorldPosition(float distance, Camera camera = null)
        {
            if (NewLeanTouch.GetCamera(ref camera) == true)
            {
                var point = new Vector3(ScreenPosition.x, ScreenPosition.y, distance);

                return(camera.ScreenToWorldPoint(point));
            }

            return(default(Vector3));
        }
Beispiel #5
0
        public Vector3 GetSnapshotWorldPosition(float targetAge, float distance, Camera camera = null)
        {
            if (NewLeanTouch.GetCamera(ref camera) == true)
            {
                var screenPosition = GetSnapshotScreenPosition(targetAge);
                var point          = new Vector3(screenPosition.x, screenPosition.y, distance);

                return(camera.ScreenToWorldPoint(point));
            }

            return(default(Vector3));
        }
Beispiel #6
0
        protected virtual void LateUpdate()
        {
            // Make sure the camera exists
            if (NewLeanTouch.GetCamera(ref Camera, gameObject) == true)
            {
                // Get the fingers we want to use
                var fingers = NewLeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

                // Reset pinch ratio before checking new pinch ratio
                var pinchRatio = prevZoom;

                // Check position of figures
                for (var i = 0; i < fingers.Count; i++)
                {
                    if (!minimapZoom && !MyCloseUpCamera.GetComponent <Camera>().enabled)
                    {
                        var checkFinger = fingers[i];
                        if (checkFinger.ScreenPosition.x > 740 && checkFinger.ScreenPosition.y < 225)
                        {
                            minimapZoom = true;
                        }
                    }
                }

                // Get script from assesment camera (which is default)
                Zoomer        ZoomerScript        = (Zoomer)AsessmentCamera.GetComponent(typeof(Zoomer));
                CloseUpCamera CloseUpCameraScript = (CloseUpCamera)MyCloseUpCamera.GetComponent(typeof(CloseUpCamera));

                if (minimapZoom)
                {
                    // Get the pinch ratio of these fingers with minimap sensativty
                    pinchRatio = NewLeanGesture.GetPinchRatio(fingers, MiniMapSensitivity);
                    // Get script from mini map camera
                    ZoomerScript = (Zoomer)MiniMapCamera.GetComponent(typeof(Zoomer));
                    // Mini map min and max zoom
                    ZoomMin = 20.0f;
                    ZoomMax = 960.0f;
                    // Reset mini map zoom
                    minimapZoom = false;
                }
                else
                {
                    // Get the pinch ratio of these fingers
                    pinchRatio = NewLeanGesture.GetPinchRatio(fingers, WheelSensitivity);
                    // Assessment camera min and max zoom
                    ZoomMin = 20.0f;
                    ZoomMax = 440.0f;
                }

                // Modify the zoom value
                Zoom *= pinchRatio;

                if (Zoom < ZoomMin)
                {
                    Zoom = ZoomMin;
                }
                else if (Zoom > ZoomMax)
                {
                    Zoom = ZoomMax;
                }

                if (pinchRatio != prevZoom)
                {
                    //Calculate percentage of zoom
                    float ZoomPercent = (Zoom - ZoomMin) / (ZoomMax - ZoomMin);
                    float distanceMin = CloseUpCameraScript.distanceMin;
                    float distanceMax = CloseUpCameraScript.distanceMax;
                    CloseUpCameraScript.distance = Mathf.Clamp((ZoomPercent * (distanceMax - distanceMin) + distanceMin), distanceMin, distanceMax);
                    ZoomerScript.UpdateSSVCameraPosition(Zoom);
                }
                Zoom     = ZoomerScript.getZoomValue();
                prevZoom = pinchRatio;
            }
        }