示例#1
0
        private void Update()
        {
            float acc = Input.GetAxis("Vertical");

            if (Mathf.Abs(acc) > 0)
            {
                speed = Mathf.Lerp(speed, maxSpeed * Mathf.Sign(acc), Time.deltaTime * Mathf.Abs(acc));
            }
            else
            {
                speed = Mathf.Lerp(speed, 0, Time.deltaTime * 0.1f);
            }

            if (Mathf.Abs(speed) < 0.1)
            {
                return;
            }

            float r = Input.GetAxis("Horizontal");

            rotation += r * Time.deltaTime * speed;
            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, speed * Time.deltaTime / 3600, rotation + 180, out lng, out lat);

            marker.rotationY = rotation;
            marker.SetPosition(lng, lat);
            if (centerOnMarker)
            {
                map.SetPosition(lng, lat);
            }
            if (rotateCamera)
            {
                OnlineMapsCameraOrbit.instance.rotation = new Vector2(OnlineMapsCameraOrbit.instance.rotation.x, rotation + 180);
            }
        }
示例#2
0
        private void Update()
        {
            if (!hasTargetPoint)
            {
                return;
            }

            double dx, dy;

            OnlineMapsUtils.DistanceBetweenPoints(lng, lat, targetLng, targetLat, out dx, out dy);

            double distance  = Math.Sqrt(dx * dx + dy * dy);
            float  cMaxSpeed = maxSpeed;

            if (distance < 0.1)
            {
                cMaxSpeed = maxSpeed * (float)(distance / 0.1);
            }

            speed = Mathf.Lerp(speed, cMaxSpeed, Time.deltaTime);

            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, speed * Time.deltaTime / 3600, rotation + 180, out lng, out lat);

            OnlineMapsUtils.DistanceBetweenPoints(lng, lat, targetLng, targetLat, out dx, out dy);
            if (Math.Sqrt(dx * dx + dy * dy) < 0.001)
            {
                hasTargetPoint = false;
                speed          = 0;
            }

            marker.rotationY = rotation;
            marker.SetPosition(lng, lat);
            if (centerOnMarker)
            {
                map.SetPosition(lng, lat);
            }

            if (lineRendererProgress < 1)
            {
                lineRendererProgress += Time.deltaTime / lineRendererDuration;

                Vector3 p1 = control.GetWorldPosition(lng, lat);
                Vector3 p2 = control.GetWorldPosition(targetLng, targetLat);
                Vector3 p3 = lineRendererProgress > 0.5 ? Vector3.Lerp(p1, p2, (lineRendererProgress - 0.5f) * 2f) : p1;
                Vector3 p4 = lineRendererProgress < 0.5 ? Vector3.Lerp(p1, p2, lineRendererProgress * 2) : p2;
                lineRenderer.SetPosition(0, p4);
                lineRenderer.SetPosition(1, p3);
            }
            else
            {
                lineRendererProgress = 1;
                if (lineRenderer.enabled)
                {
                    lineRenderer.enabled = false;
                }
            }
        }
        /// <summary>
        /// This method is called when a user clicks on a map
        /// </summary>
        private void OnMapClick()
        {
            // Get the coordinates under cursor
            double lng, lat;

            OnlineMapsControlBase.instance.GetCoords(out lng, out lat);

            // Create a new marker under cursor
            OnlineMapsMarkerManager.CreateItem(lng, lat, "Marker " + OnlineMapsMarkerManager.CountItems);

            OnlineMaps map = OnlineMaps.instance;

            // Get the coordinate at the desired distance
            double nlng, nlat;

            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, radiusKM, 90, out nlng, out nlat);

            double tx1, ty1, tx2, ty2;

            // Convert the coordinate under cursor to tile position
            map.projection.CoordinatesToTile(lng, lat, 20, out tx1, out ty1);

            // Convert remote coordinate to tile position
            map.projection.CoordinatesToTile(nlng, nlat, 20, out tx2, out ty2);

            // Calculate radius in tiles
            double r = tx2 - tx1;

            // Create a new array for points
            OnlineMapsVector2d[] points = new OnlineMapsVector2d[segments];

            // Calculate a step
            double step = 360d / segments;

            // Calculate each point of circle
            for (int i = 0; i < segments; i++)
            {
                double px = tx1 + Math.Cos(step * i * OnlineMapsUtils.Deg2Rad) * r;
                double py = ty1 + Math.Sin(step * i * OnlineMapsUtils.Deg2Rad) * r;
                map.projection.TileToCoordinates(px, py, 20, out lng, out lat);
                points[i] = new OnlineMapsVector2d(lng, lat);
            }

            // Create a new polygon to draw a circle
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(points, Color.red, 3));
        }