示例#1
0
 /// <summary>
 /// Updates the city scale.
 /// </summary>
 public void ScaleCities()
 {
     if (citiesLayer != null)
     {
         CityScaler scaler = citiesLayer.GetComponent <CityScaler>();
         if (scaler != null)
         {
             scaler.ScaleCities();
         }
     }
 }
示例#2
0
        /// <summary>
        /// Redraws the cities. This is automatically called by Redraw(). Used internally by the Map Editor. You should not need to call this method directly.
        /// </summary>
        public void DrawCities()
        {
            // Create cities layer
            Transform t = transform.FindChild("Cities");

            if (t != null)
            {
                DestroyImmediate(t.gameObject);
            }
            citiesLayer = new GameObject("Cities");
            citiesLayer.transform.SetParent(transform, false);

            // Draw city marks
            _numCitiesDrawn = 0;
            int minPopulation = _minPopulation * 1000;

            for (int k = 0; k < cities.Count; k++)
            {
                City city = cities [k];
                if (city.population >= minPopulation)
                {
                    GameObject cityObj = Instantiate(citySpot);
                    cityObj.GetComponent <Renderer> ().sharedMaterial = citiesMat;
                    CityInfo cityInfo = cityObj.GetComponent <CityInfo> ();
                    cityInfo.city = city;
                    cityInfo.wmp  = this;
                    cityObj.name  = k.ToString();
                    cityObj.transform.SetParent(citiesLayer.transform, false);
                    cityObj.transform.localPosition = city.unitySphereLocation;                     // * 1.001f;
                    cityObj.transform.LookAt(transform.position);
                    cityObj.hideFlags = HideFlags.HideInHierarchy;
                    _numCitiesDrawn++;
                }
            }

            // Toggle cities layer visibility according to settings
            citiesLayer.SetActive(_showCities);

            CityScaler cityScaler = citiesLayer.GetComponent <CityScaler>() ?? citiesLayer.AddComponent <CityScaler>();

            cityScaler.map = this;
            cityScaler.ScaleCities();
        }
示例#3
0
        /// <summary>
        /// Redraws the cities. This is automatically called by Redraw(). Used internally by the Map Editor. You should not need to call this method directly.
        /// </summary>
        public void DrawCities()
        {
            if (!_showCities || !gameObject.activeInHierarchy)
            {
                return;
            }

            // Create cities layer
            Transform t = transform.FindChild("Cities");

            if (t != null)
            {
                DestroyImmediate(t.gameObject);
            }
            citiesLayer = new GameObject("Cities");
            citiesLayer.transform.SetParent(transform, false);
            if (_earthInvertedMode)
            {
                citiesLayer.transform.localScale *= 0.99f;
            }

            // Create cityclass parents
            GameObject countryCapitals = new GameObject("Country Capitals");

            countryCapitals.hideFlags = HideFlags.DontSave;
            countryCapitals.transform.SetParent(citiesLayer.transform, false);
            GameObject regionCapitals = new GameObject("Region Capitals");

            regionCapitals.hideFlags = HideFlags.DontSave;
            regionCapitals.transform.SetParent(citiesLayer.transform, false);
            GameObject normalCities = new GameObject("Normal Cities");

            normalCities.hideFlags = HideFlags.DontSave;
            normalCities.transform.SetParent(citiesLayer.transform, false);

            // Draw city marks
            _numCitiesDrawn = 0;
            int minPopulation = _minPopulation * 1000;
            int visibleCount  = 0;

            // flip localscale.x to prevent transform issues
            if (_earthInvertedMode)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            for (int k = 0; k < cities.Count; k++)
            {
                City    city    = cities [k];
                Country country = countries[city.countryIndex];
                city.isShown = !country.hidden && ((((int)city.cityClass & _cityClassAlwaysShow) != 0) || (minPopulation == 0 || city.population >= minPopulation));
                if (city.isShown)
                {
                    GameObject cityObj, cityParent;
                    switch (city.cityClass)
                    {
                    case CITY_CLASS.COUNTRY_CAPITAL:
                        cityObj = Instantiate(citySpotCapitalCountry);
                        cityObj.GetComponent <Renderer> ().sharedMaterial = citiesCountryCapitalMat;
                        cityParent = countryCapitals;
                        break;

                    case CITY_CLASS.REGION_CAPITAL:
                        cityObj = Instantiate(citySpotCapitalRegion);
                        cityObj.GetComponent <Renderer> ().sharedMaterial = citiesRegionCapitalMat;
                        cityParent = regionCapitals;
                        break;

                    default:
                        cityObj = Instantiate(citySpot);
                        cityObj.GetComponent <Renderer> ().sharedMaterial = citiesNormalMat;
                        cityParent = normalCities;
                        break;
                    }
                    cityObj.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;
                    cityObj.name      = k.ToString();
                    cityObj.transform.SetParent(cityParent.transform, false);
                    cityObj.transform.localPosition = city.unitySphereLocation;                     // transform.TransformPoint(city.unitySphereLocation);
                    if (_earthInvertedMode)
                    {
                        cityObj.transform.LookAt(transform.TransformPoint(city.unitySphereLocation * 2));
                    }
                    else
                    {
                        cityObj.transform.LookAt(transform.position);
                    }
                    _numCitiesDrawn++;
                    visibleCount++;
                }
            }

            if (_earthInvertedMode)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            // Cache visible cities (this is faster than iterate through the entire collection)
            if (visibleCities == null || visibleCities.Length != visibleCount)
            {
                visibleCities = new City[visibleCount];
            }
            for (int k = 0; k < cities.Count; k++)
            {
                City city = cities[k];
                if (city.isShown)
                {
                    visibleCities[--visibleCount] = city;
                }
            }

            // Toggle cities layer visibility according to settings
            citiesLayer.SetActive(_showCities);

            CityScaler cityScaler = citiesLayer.GetComponent <CityScaler>() ?? citiesLayer.AddComponent <CityScaler>();

            cityScaler.map = this;
            cityScaler.ScaleCities();
        }