コード例 #1
0
        IEnumerator TransferCountry()
        {
            // Reset map
            map.ReloadData();
            map.Redraw();

            // Countries in action
            string targetCountry      = "Czech Republic";
            string sourceCountry      = "Slovakia";
            int    targetCountryIndex = map.GetCountryIndex(targetCountry);
            int    sourceCountryIndex = map.GetCountryIndex(sourceCountry);

            if (sourceCountryIndex < 0 || targetCountryIndex < 0)
            {
                Debug.Log("Countries not found.");
                yield break;
            }

            // Step 1: Mark countries
            map.FlyToCountry(sourceCountry, 1f, 0.05f);
            map.BlinkCountry(sourceCountry, Color.white, Color.red, 2f, 0.15f);
            yield return(new WaitForSeconds(1f));

            // Step 2: Add animated line
            LineMarkerAnimator lma = map.AddLine(new Vector2[]
            {
                map.countries[sourceCountryIndex].center,
                map.countries[targetCountryIndex].center
            }, Color.yellow, 2f, 0.15f);

            lma.dashInterval          = 0.0005f;
            lma.dashAnimationDuration = 0.3f;
            lma.drawingDuration       = 2.5f;
            lma.autoFadeAfter         = 0.5f;
            lma.fadeOutDuration       = 0f;
            yield return(new WaitForSeconds(3f));

            // Step 3: Transfer Slovakia to Czech Republic
            Region sourceRegion = map.GetCountry("Slovakia").mainRegion;

            if (!map.CountryTransferCountryRegion(targetCountryIndex, sourceRegion, false))
            {
                Debug.LogError("Country could not be transferred.");
                yield break;
            }

            // Step 4: rename Czech Republic to Czechoslovakia
            if (!map.CountryRename("Czech Republic", "Czechoslovakia"))
            {
                Debug.LogError("Country could not be renamed.");
            }

            // Step 5: refresh any change on screen and highlight the new country
            map.Redraw();
            map.BlinkCountry("Czechoslovakia", Color.white, Color.blue, 2f, 0.15f);
        }
コード例 #2
0
        /// <summary>
        /// This event function is called by the country dropdown script. It has been linked on the UI directly.
        /// </summary>
        public void CountrySelected(int index)
        {
            string countryName = countriesDropdown.options [index].text;

            map.BlinkCountry(countryName, Color.red, Color.yellow, 3f, 0.2f);

            PopulateProvinces(countryName);
        }
コード例 #3
0
        void FlyToCountry(int countryIndex)
        {
            // Get zoom level for the extents of the country
            float zoomLevel = map.GetCountryRegionZoomExtents(countryIndex);

            map.FlyToCountry(countryIndex, 2.0f, zoomLevel);
            map.BlinkCountry(countryIndex, Color.green, Color.black, 3.0f, 0.2f);
        }
コード例 #4
0
        IEnumerator TransferProvinces()
        {
            // Reset map
            map.ReloadData();
            map.Redraw();

            // Transfer some German provinces to Poland
            int countryIndex = map.GetCountryIndex("Poland");

            // Step 1: Focus on area of provinces
            map.showProvinces    = true;
            map.drawAllProvinces = true;
            map.FlyToProvince("Germany", "Brandenburg", 1f, 0.04f);
            yield return(new WaitForSeconds(1f));

            // Step 2: Mark provinces
            string[] provincesToTransfer = new string[] {
                "Brandenburg",
                "Mecklenburg-Vorpommern",
                "Sachsen-Anhalt",
                "Sachsen",
                "Thüringen"
            };
            foreach (string provinceName in provincesToTransfer)
            {
                int provinceIndex = map.GetProvinceIndex("Germany", provinceName);
                map.BlinkProvince(provinceIndex, Color.white, Color.red, 2f, 0.15f);
                LineMarkerAnimator lma = map.AddLine(new Vector2[] {
                    map.provinces [provinceIndex].center,
                    map.countries [countryIndex].center
                }, Color.yellow, 1f, 0.15f);
                lma.dashInterval          = 0.0001f;
                lma.dashAnimationDuration = 0.3f;
                lma.drawingDuration       = 2.5f;
                lma.autoFadeAfter         = 0.5f;
                lma.fadeOutDuration       = 0f;
            }
            yield return(new WaitForSeconds(3f));

            // Step 3: transfer some German provinces to Poland
            foreach (string provinceName in provincesToTransfer)
            {
                Province province = map.GetProvince(provinceName, "Germany");
                if (!map.CountryTransferProvinceRegion(countryIndex, province.mainRegion, false))
                {
                    Debug.LogError("Could not transfer province " + provinceName + " to Poland.");
                }
            }
            map.Redraw();

            // End

            map.FlyToCountry("Poland", 1f, 0.04f);
            map.BlinkCountry("Poland", Color.white, Color.green, 2f, 0.15f);

            Debug.Log("Done.");
        }
コード例 #5
0
        public void CountrySelected(int index)
        {
            string countryName = countryNames [index];

            map.BlinkCountry(countryName, Color.red, Color.yellow, 2f, 0.3f);

            Country country = map.GetCountry(countryName);

            resourcesInputField.text = country.attrib [RESOURCE_NAME];
        }
コード例 #6
0
        void ChangeCountryOwnerShip(float x, float y) {
            int countryIndex = map.GetCountryIndex(new Vector2(x, y));
            if (countryIndex < 0)
                return;
            Country country = map.countries[countryIndex];
            if (country.attrib["player"] == 1) {
                country.attrib["player"] = 2;
            } else {
                country.attrib["player"] = 1;
            }
            UpdatePathFindingMatrixCost();  // need to update cost matrix

            PaintCountries();
            map.BlinkCountry(countryIndex, player1Color, player2Color, 1f, 0.1f);
        }
コード例 #7
0
        void OnGUI()
        {
            if (avoidGUI)
            {
                return;
            }

            // Do autoresizing of GUI layer
            GUIResizer.AutoResize();

            // Check whether a country or city is selected, then show a label with the entity name and its neighbours (new in V4.1!)
            if (map.countryHighlighted != null || map.cityHighlighted != null || map.provinceHighlighted != null)
            {
                string text;
                if (map.cityHighlighted != null)
                {
                    if (!map.cityHighlighted.name.Equals(map.cityHighlighted.province))   // show city name + province & country name
                    {
                        text = "City: " + map.cityHighlighted.name + " (" + map.cityHighlighted.province + ", " + map.countries[map.cityHighlighted.countryIndex].name + ")";
                    }
                    else        // show city name + country name (city is a capital with same name as province)
                    {
                        text = "City: " + map.cityHighlighted.name + " (" + map.countries[map.cityHighlighted.countryIndex].name + ")";
                    }
                }
                else if (map.provinceHighlighted != null)
                {
                    text = map.provinceHighlighted.name + ", " + map.countryHighlighted.name;
                    List <Province> neighbours = map.ProvinceNeighboursOfCurrentRegion();
                    if (neighbours.Count > 0)
                    {
                        text += "\n" + EntityListToString <Province>(neighbours);
                    }
                }
                else if (map.countryHighlighted != null)
                {
                    text = map.countryHighlighted.name + " (" + map.countryHighlighted.continent + ")";
                    List <Country> neighbours = map.CountryNeighboursOfCurrentRegion();
                    if (neighbours.Count > 0)
                    {
                        text += "\n" + EntityListToString <Country>(neighbours);
                    }
                }
                else
                {
                    text = "";
                }
                float x, y;
                if (minimizeState)
                {
                    x = Screen.width - 130;
                    y = Screen.height - 140;
                }
                else
                {
                    x = Screen.width / 2.0f;
                    y = Screen.height - 40;
                }
                // shadow
                GUI.Label(new Rect(x - 1, y - 1, 0, 10), text, labelStyleShadow);
                GUI.Label(new Rect(x + 1, y + 2, 0, 10), text, labelStyleShadow);
                GUI.Label(new Rect(x + 2, y + 3, 0, 10), text, labelStyleShadow);
                GUI.Label(new Rect(x + 3, y + 4, 0, 10), text, labelStyleShadow);
                // texst face
                GUI.Label(new Rect(x, y, 0, 10), text, labelStyle);
            }

            // Assorted options to show/hide frontiers, cities, Earth and enable country highlighting
            GUI.Box(new Rect(0, 0, 150, 200), "");
            map.showFrontiers          = GUI.Toggle(new Rect(10, 20, 150, 30), map.showFrontiers, "Toggle Frontiers");
            map.showEarth              = GUI.Toggle(new Rect(10, 50, 150, 30), map.showEarth, "Toggle Earth");
            map.showCities             = GUI.Toggle(new Rect(10, 80, 150, 30), map.showCities, "Toggle Cities");
            map.showCountryNames       = GUI.Toggle(new Rect(10, 110, 150, 30), map.showCountryNames, "Toggle Labels");
            map.enableCountryHighlight = GUI.Toggle(new Rect(10, 140, 170, 30), map.enableCountryHighlight, "Enable Highlight");

            // buttons background color
            GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f);

            // Add button to toggle Earth texture
            if (GUI.Button(new Rect(10, 170, 160, 30), "  Change Earth style", buttonStyle))
            {
                map.earthStyle = (EARTH_STYLE)(((int)map.earthStyle + 1) % 4);
            }

            // Add buttons to show the color picker and change colors for the frontiers or fill
            if (GUI.Button(new Rect(10, 210, 160, 30), "  Change Frontiers Color", buttonStyle))
            {
                colorPicker.showPicker = true;
                changingFrontiersColor = true;
            }
            if (GUI.Button(new Rect(10, 250, 160, 30), "  Change Fill Color", buttonStyle))
            {
                colorPicker.showPicker = true;
                changingFrontiersColor = false;
            }
            if (colorPicker.showPicker)
            {
                if (changingFrontiersColor)
                {
                    map.frontiersColor = colorPicker.setColor;
                }
                else
                {
                    map.fillColor = colorPicker.setColor;
                }
            }

            // Add a button which demonstrates the navigateTo functionality -- pass the name of a country
            // For a list of countries and their names, check map.Countries collection.
            if (GUI.Button(new Rect(10, 290, 180, 30), "  Fly to Australia (Country)", buttonStyle))
            {
                FlyToCountry("Australia");
            }
            if (GUI.Button(new Rect(10, 325, 180, 30), "  Fly to Mexico (Country)", buttonStyle))
            {
                FlyToCountry("Mexico");
            }
            if (GUI.Button(new Rect(10, 360, 180, 30), "  Fly to New York (City)", buttonStyle))
            {
                FlyToCity("New York", "United States of America");
            }
            if (GUI.Button(new Rect(10, 395, 180, 30), "  Fly to Madrid (City)", buttonStyle))
            {
                FlyToCity("Madrid", "Spain");
            }


            // Slider to show the new set zoom level API in V4.1
            GUI.Button(new Rect(10, 430, 85, 30), "  Zoom Level", buttonStyle);
            float prevZoomLevel = zoomLevel;

            GUI.backgroundColor = Color.white;
            zoomLevel           = GUI.HorizontalSlider(new Rect(100, 445, 80, 85), zoomLevel, 0, 1, sliderStyle, sliderThumbStyle);
            GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f);
            if (zoomLevel != prevZoomLevel)
            {
                prevZoomLevel = zoomLevel;
                map.SetZoomLevel(zoomLevel);
            }

            if (GUI.Button(new Rect(10, 475, 180, 30), "  Alpha Texture Fill", buttonStyle))
            {
                TransparentTextureFill();
            }



            // Add a button to colorize countries
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 20, 180, 30), "  Colorize Europe", buttonStyle))
            {
                for (int countryIndex = 0; countryIndex < map.countries.Length; countryIndex++)
                {
                    if (map.countries[countryIndex].continent.Equals("Europe"))
                    {
                        Color color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 0.5f);
                        map.ToggleCountrySurface(countryIndex, true, color);
                    }
                }
            }

            // Colorize random country and fly to it
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 60, 180, 30), "  Colorize Random", buttonStyle))
            {
                int   countryIndex = Random.Range(0, map.countries.Length);
                Color color        = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
                map.ToggleCountrySurface(countryIndex, true, color);
                map.BlinkCountry(countryIndex, Color.green, Color.black, 0.8f, 0.2f);
            }

            // Add a button to colorize countries
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 100, 180, 30), "  Colorize Continents", buttonStyle))
            {
                Dictionary <string, Color> continentColors = new Dictionary <string, Color>();
                for (int countryIndex = 0; countryIndex < map.countries.Length; countryIndex++)
                {
                    Country country = map.countries[countryIndex];
                    Color   continentColor;
                    if (continentColors.ContainsKey(country.continent))
                    {
                        continentColor = continentColors[country.continent];
                    }
                    else
                    {
                        continentColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 0.5f);
                        continentColors.Add(country.continent, continentColor);
                    }
                    map.ToggleCountrySurface(countryIndex, true, continentColor);
                }
            }


            // Button to clear colorized countries
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 140, 180, 30), "  Reset countries", buttonStyle))
            {
                map.HideCountrySurfaces();
            }

            // Tickers sample
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 180, 180, 30), "  Tickers Sample", buttonStyle))
            {
                TickerSample();
            }

            // Decorator sample
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 220, 180, 30), "  Texture Sample", buttonStyle))
            {
                TextureSample();
            }

            // Moving the Earth sample
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 260, 180, 30), "  Toggle Minimize", buttonStyle))
            {
                ToggleMinimize();
            }

            // Add marker sample (Sprite)
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 300, 180, 30), "  Add Marker (2D Sprite)", buttonStyle))
            {
                AddMarkerSpriteOnRandomCity();
            }

            // Add marker sample (Game Object)
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 340, 180, 30), "  Add Marker (Game Object)", buttonStyle))
            {
                AddMarker3DObjectOnRandomCity();
            }

            // Add marker sample (Text)
            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 380, 180, 30), "  Add Marker (Text)", buttonStyle))
            {
                AddMarkerTextOnRandomPlace();
            }

            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 420, 180, 30), "  Add Trajectories", buttonStyle))
            {
                AddTrajectories();
            }

            if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 460, 180, 30), "  One Country Borders", buttonStyle))
            {
                ShowCountryBorders();
            }
        }