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.");
        }
Example #2
0
        void HandleOnCellClick(int cellIndex)
        {
            Debug.Log("Clicked cell: " + cellIndex);

            switch (selectionMode)
            {
            case SELECTION_MODE.CUSTOM_PATH:
                if (selectionState == 0)
                {
                    firstCell = cellIndex;
                    map.SetCellColor(firstCell, Color.green, true);
                    selectionState = 1;
                }
                else
                {
                    DrawPath(firstCell, cellIndex);
                    selectionState = 0;
                }
                break;

            case SELECTION_MODE.CUSTOM_COST:
                if (selectionState == 0)
                {
                    firstCell = cellIndex;
                    map.SetCellColor(firstCell, Color.green, true);
                    selectionState = 1;
                }
                else
                {
                    // Assign crossing cost between previously selected cell and clicked cell
                    map.SetCellNeighbourCost(firstCell, cellIndex, 1000, true);
                    // Draw a line
                    Vector3[] points = map.GetCellSharedEdge(firstCell, cellIndex);
                    if (points != null)
                    {
                        map.ClearCells(true, false, false);
                        map.AddLine(points [0], points [1], Color.yellow, 0, 0, 0.002f, 0);
                        // Switch selection mode back to select first cell
                    }
                    selectionState = 0;
                }
                break;
            }
        }
        /// <summary>
        /// Example of how to add custom lines to the map
        /// Similar to the AddMarker functionality, you need two spherical coordinates and then call AddLine
        /// </summary>
        void AddTrajectories(int numberOfLines)
        {
            // In this example we will add random lines from a group of cities to another cities (see AddMaker example above for other options to get locations)
            for (int line = 0; line < numberOfLines; line++)
            {
                // Get two random cities
                int city1 = Random.Range(0, map.cities.Count);
                int city2 = Random.Range(0, map.cities.Count);

                // Get their sphere-coordinates
                Vector3 start = map.cities [city1].unitySphereLocation;
                Vector3 end   = map.cities [city2].unitySphereLocation;

                // Add lines with random color, speeds and elevation
                Color color           = new Color(Random.Range(0.5f, 1), Random.Range(0.5f, 1), Random.Range(0.5f, 1));
                float elevation       = Random.Range(0, 0.5f);                  // elevation is % relative to the Earth radius
                float drawingDuration = 4.0f;
                float lineWidth       = 0.0025f;
                float fadeAfter       = 2.0f;           // line stays for 2 seconds, then fades out - set this to zero to avoid line removal
                map.AddLine(start, end, color, elevation, drawingDuration, lineWidth, fadeAfter);
            }
        }
Example #4
0
        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++;
        }
Example #5
0
 GameObject AddSphericalLine(Vector3 start, Vector3 end, Color color, float drawTime, float width)
 {
     return(map.AddLine(start, end, color, 0.005f, drawTime, width, 0.0f));
 }