Example #1
0
        void SortCitiesByPopulation()
        {
            List <City> sortedCities = new List <City> (map.cities);

            sortedCities.Sort(PopulationComparer);

            Debug.Log("Less populated city: " + map.GetCityFullName(sortedCities [0]));
            Debug.Log("Most populated city: " + map.GetCityFullName(sortedCities [sortedCities.Count - 1]));
        }
        void NewPath()
        {
            // Create a path consisting of a list of latitude/longitudes
            const int      numLocations = 20;
            List <Vector2> latLonList   = new List <Vector2> (numLocations);

            // Starting city - calling GetCityIndex without parameters returns a random visible city index
            int cityIndex = map.GetCityIndex();

            Debug.Log("Path started on " + map.GetCityFullName(cityIndex));

            // Add the city lat/lon coordinates to the list
            latLonList.Add(map.cities [cityIndex].latlon);

            // Add more cities - we'll take the 20 nearest cities
            List <int> excludeList = new List <int> (numLocations);

            excludeList.Add(cityIndex);

            for (int k = 1; k < numLocations; k++)
            {
                // Get the nearest city
                cityIndex = map.GetCityIndex(map.cities [cityIndex].latlon, excludeList);
                excludeList.Add(cityIndex);
                latLonList.Add(map.cities [cityIndex].latlon);
            }

            // Create the moving gameobject
            if (anim != null)
            {
                Destroy(anim.gameObject);
            }
            GameObject obj = Instantiate <GameObject>(prefab);

            obj.transform.localScale = Vector3.one * 0.1f;

            // Add a GlobePos animator
            anim        = obj.AddComponent <GlobePosAnimator> ();
            anim.latLon = latLonList;

            // Refresh path
            anim.DrawPath();

            // Update current position
            anim.MoveTo(progress);
        }