using Plugins.Gis.Gps; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; public class DronePathRenderer : MonoBehaviour { private LineRenderer lineRenderer; private OnlineMapsTileSetControl control; private OnlineMaps map; public List positions; public int droneID; public Color color = new Color(); public int nb; private void Start() { map = OnlineMaps.instance; control = OnlineMapsTileSetControl.instance; lineRenderer = gameObject.AddComponent(); lineRenderer.widthCurve = AnimationCurve.Constant(0, 1, 10); lineRenderer.positionCount = 0; lineRenderer.material.color = color; lineRenderer.receiveShadows = false; lineRenderer.shadowCastingMode = ShadowCastingMode.Off; lineRenderer.material.shader = Shader.Find("Unlit/Texture_color"); lineRenderer.startWidth = 3; lineRenderer.endWidth = 3; control.OnMeshUpdated += OnMeshUpdated; control.OnSmoothZoomProcess += OnSmoothZoomProcess; } public void setColor(Color c) { color = c; } public void AddPosition(GpsCoordinates pos) { positions.Add(pos); Debug.Log("Add to " + droneID); } private Vector3 GetWorldPositionWithAltitude(GpsCoordinates pos) { double lng = pos.Longitude; double lat = pos.Latitude; float altitude = (float)pos.Altitude; double tlx, tly, brx, bry; map.GetCorners(out tlx, out tly, out brx, out bry); Vector3 p; if (altitude > 0) { p = OnlineMapsTileSetControl.instance.GetWorldPosition(lng, lat); float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry); p.y = altitude * yScale; if (control.elevationBottomMode == OnlineMapsTileSetControl.ElevationBottomMode.minValue) p.y -= control.elevationMinValue * yScale; p.y *= control.elevationScale; } else p = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(lng, lat, tlx, tly, brx, bry); return p; } private void OnMeshUpdated() { UpdateLineRenderer(); } private void OnSmoothZoomProcess() { Debug.Log("zooming"); UpdateLineRenderer(); } public void UpdateLineRenderer() { Vector3[] points = new Vector3[positions.Count]; lineRenderer.positionCount = positions.Count; nb = positions.Count; for (int i = 0; i < positions.Count; i++) { points[i] = GetWorldPositionWithAltitude(positions[i]); } lineRenderer.SetPositions(points); } }