public void DrawPath() { RemovePath(); for (int k = 0; k < latLon.Count - 1; k++) { Vector2 latLonStart = latLon [k]; Vector2 latLonEnd = latLon [k + 1]; LineMarkerAnimator line = map.AddLine(latLonStart, latLonEnd, Color.white, 0f, 0f, 0.05f, 0); pathLines.Add(line.gameObject); } // Compute path length int steps = latLon.Count; stepLengths = new float[steps]; // Calculate total travel length totalLength = 0; for (int k = 0; k < steps - 1; k++) { stepLengths [k] = map.calc.Distance(latLon [k], latLon [k + 1]); totalLength += stepLengths [k]; } Debug.Log("Total path length = " + totalLength / 1000 + " km."); }
/// <summary> /// Adds a line to the globe along a set of points with options (returns the line gameobject). /// </summary> /// <param name="latlon">sequence of map coordinates</param> /// <param name="Color">line color</param> /// <param name="arcElevation">arc elevation relative to the sphere size (0-1 range).</param> /// <param name="duration">drawing speed (0 for instant drawing)</param> /// <param name="fadeOutAfter">duration of the line once drawn after which it fades out (set this to 0 to make the line stay forever)</param> /// <param name="reuseMaterial">If the provided material should be instantiated. Set this to true to reuse given material and avoid instantiation.</param> public LineMarkerAnimator AddLine(Vector2[] latlon, Color color, float lineWidth) { CheckMarkersLayer(); GameObject newLine = new GameObject("MarkerLine"); newLine.transform.SetParent(markersLayer.transform, false); LineMarkerAnimator lma = newLine.AddComponent <LineMarkerAnimator> (); lma.SetVertices(latlon); lma.color = color; lma.lineWidth = lineWidth; lma.lineMaterial = markerMatLine; lma.earthInvertedMode = _earthInvertedMode; return(lma); }
/// <summary> /// Adds a line to the globe along a set of points with options (returns the line gameobject). /// </summary> /// <param name="latlon">sequence of map coordinates</param> /// <param name="Color">line color</param> /// <param name="arcElevation">arc elevation relative to the sphere size (0-1 range).</param> /// <param name="duration">drawing speed (0 for instant drawing)</param> /// <param name="fadeOutAfter">duration of the line once drawn after which it fades out (set this to 0 to make the line stay forever)</param> /// <param name="reuseMaterial">If the provided material should be instantiated. Set this to true to reuse given material and avoid instantiation.</param> public LineMarkerAnimator AddLine(Vector2[] latlon, Color color, float lineWidth, float arcElevation, float duration, float fadeOutAfter, bool reuseMaterial) { CheckMarkersLayer(); GameObject newLine = new GameObject("MarkerLine"); newLine.transform.SetParent(markersLayer.transform, false); LineMarkerAnimator lma = newLine.AddComponent <LineMarkerAnimator> (); lma.SetVertices(latlon); lma.color = color; lma.arcElevation = arcElevation; lma.duration = duration; lma.lineWidth = lineWidth; lma.lineMaterial = markerMatLine; lma.autoFadeAfter = fadeOutAfter; lma.earthInvertedMode = _earthInvertedMode; lma.reuseMaterial = reuseMaterial; return(lma); }
/// <summary> /// Adds a line to the globe with options (returns the line gameobject). /// </summary> /// <param name="start">starting location on the sphere</param> /// <param name="end">end location on the sphere</param> /// <param name="Color">line color</param> /// <param name="arcElevation">arc elevation relative to the sphere size.</param> /// <param name="duration">drawing speed (0 for instant drawing)</param> /// <param name="fadeOutAfter">duration of the line once drawn after which it fades out (set this to 0 to make the line stay forever)</param> public GameObject AddLine(Vector3 start, Vector3 end, Color color, float arcElevation, float duration, float lineWidth, float fadeOutAfter) { CheckMarkersLayer(); GameObject newLine = new GameObject("MarkerLine"); newLine.transform.SetParent(markersLayer.transform, false); LineMarkerAnimator lma = newLine.AddComponent <LineMarkerAnimator>(); lma.start = start; lma.end = end; lma.color = color; lma.arcElevation = arcElevation; lma.duration = duration; lma.lineWidth = lineWidth; lma.lineMaterial = markerMat; lma.autoFadeAfter = fadeOutAfter; lma.earthInvertedMode = _earthInvertedMode; return(newLine); }
void BuildRoad() { // Get a path between both cities List <int> cellIndices = null; do { // Find 2 random cities in Europe int city1Index = GetRandomEuropeanCity(); int city2Index = GetRandomEuropeanCity(); // Underline cell indices? int cell1Index = map.GetCellIndex(map.GetCity(city1Index).latlon); int cell2Index = map.GetCellIndex(map.GetCity(city2Index).latlon); if (cell1Index == cell2Index) { continue; } // Get the path cellIndices = map.FindPath(cell1Index, cell2Index, 0, true); } while(cellIndices == null); // Highlight road cells StartCoroutine(IlluminateRoadCells(cellIndices)); // Get lat/lon coordinates for the path int positionsCount = cellIndices.Count; Vector2[] latLons = new Vector2[positionsCount]; for (int k = 0; k < positionsCount; k++) { latLons [k] = map.cells [cellIndices [k]].latlonCenter; } // Build a road along the map coordinates LineMarkerAnimator lma = map.AddLine(latLons, Color.white, 0.1f); lma.lineMaterial.mainTexture = roadTexture; lma.lineMaterial.mainTextureScale = new Vector2(2f, 1f); // Go to there! map.FlyToLocation(latLons [0].x, latLons [0].y, 1f, 0.2f); }
void Bounce(Vector2 latlonStart) { // Spread to another near city int anotherCity = 0; float minDist = float.MaxValue; for (int k = 0; k < 25; k++) { int c = Random.Range(0, map.cities.Count); float dist = map.calc.Distance(latlonStart, map.cities [c].latlon); if (dist < minDist) { anotherCity = c; minDist = dist; } } Vector2 dest = map.cities [anotherCity].latlon; LineMarkerAnimator line = map.AddLine(latlonStart, dest, Color.yellow, 0.1f, 2f, 0.05f, 0.1f); line.OnLineDrawingEnd += (LineMarkerAnimator lma) => { StartCoroutine(Spread(anotherCity)); }; bounces++; }