Esempio n. 1
0
        void MoveCity(string countryName, string cityName, Vector3 cityLocation)
        {
            City city = map.GetCity(map.countries, countryName, cityName);

            city.unitySphereLocation = cityLocation;
            map.Redraw();
        }
Esempio n. 2
0
        void Start()
        {
            labelStyle = new GUIStyle();
            labelStyle.normal.textColor = Color.white;
            buttonStyle                        = new GUIStyle(labelStyle);
            buttonStyle.alignment              = TextAnchor.MiddleLeft;
            buttonStyle.normal.background      = Texture2D.whiteTexture;
            buttonStyle.normal.textColor       = Color.white;
            sliderStyle                        = new GUIStyle();
            sliderStyle.normal.background      = Texture2D.whiteTexture;
            sliderStyle.fixedHeight            = 4.0f;
            sliderThumbStyle                   = new GUIStyle();
            sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb");
            sliderThumbStyle.overflow          = new RectOffset(0, 0, 8, 0);
            sliderThumbStyle.fixedWidth        = 20.0f;
            sliderThumbStyle.fixedHeight       = 12.0f;


            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);

            // Get map instance to Globe API methods
            map         = WorldMapGlobe.instance;
            map.OnDrag += ClearFoW;

            // Load prefab
            GameObject tower = Resources.Load <GameObject>("Tower/Tower");

            // Colorize some countries
            for (int colorizeIndex = 0; colorizeIndex < map.countries.Length; colorizeIndex++)
            {
                Country country = map.countries[colorizeIndex];
                if (country.continent.Equals("Europe"))
                {
                    // Color country surface
                    Color color = new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), 0.2f);
                    map.ToggleCountrySurface(country.name, true, color);

                    // Clear fog around the country
                    map.SetFogOfWarAlpha(country, 0, 0.1f);

                    // Add a random moving sphere for this country
                    GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    obj.transform.SetParent(map.transform, false);
                    obj.transform.localScale    = Vector3.one * 0.02f;
                    obj.transform.localPosition = country.sphereCenter;
                    obj.AddComponent <AnimateSphereAround>();
                    // Set a random color for the sphere
                    obj.GetComponent <Renderer>().material.color = new Color(Random.value, Random.value, Random.value);

                    // Add a tower on the center of the country
                    GameObject thisTower = Instantiate(tower);
                    map.AddMarker(thisTower, country.sphereCenter, 0.15f, false, 0, true);
                }
            }

            // Center on Paris
            map.FlyToCity(map.GetCity("France", "Paris"));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        void AddPanel()
        {
            // If previous panel exists, destroy it
            if (currentPanel != null)
            {
                Destroy(currentPanel);
            }

            // Instantiate panel
            currentPanel = Instantiate <GameObject> (prefab);

            // Update panel texts
            Text countryName, provinceName, cityName, population;

            countryName  = currentPanel.transform.Find("Panel/RowCountry/CountryName").GetComponent <Text> ();
            provinceName = currentPanel.transform.Find("Panel/RowProvince/ProvinceName").GetComponent <Text> ();
            cityName     = currentPanel.transform.Find("Panel/RowCity/CityName").GetComponent <Text> ();
            population   = currentPanel.transform.Find("Panel/RowCityData1/CityData1Value").GetComponent <Text> ();

            // Gets a random city and populate data
            int  cityIndex = Random.Range(0, map.cities.Count - 1);
            City city      = map.GetCity(cityIndex);

            cityName.text     = city.name;
            population.text   = city.population.ToString();
            countryName.text  = map.GetCityCountryName(cityIndex);
            provinceName.text = map.GetCityProvinceName(cityIndex);

            // Position the canvas over the globe
            float   distaceToGlobeCenter = 1.2f;
            Vector3 worldPos             = map.transform.TransformPoint(city.unitySphereLocation * distaceToGlobeCenter);

            currentPanel.transform.position = worldPos;

            // Draw a circle around the city
            map.AddMarker(MARKER_TYPE.CIRCLE_PROJECTED, city.unitySphereLocation, 100, 0.8f, 1f, Color.green);

            // Parent the panel to the globe so it rotates with it
            currentPanel.transform.SetParent(map.transform, true);

            // Finally fly to city to show the panel
            map.FlyToCity(cityIndex, 2f);
        }