示例#1
0
        void Start()
        {
            // UI Setup - non-important, only for this demo
            labelStyle                        = new GUIStyle();
            labelStyle.alignment              = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor       = Color.white;
            labelStyleShadow                  = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor = Color.black;

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

            // WMSK setup
            map = WMSK.instance;
            map.OnCountryClick += HandleOnCountryClick;
            map.OnCountryEnter += HandleOnCountryEnter;

            // Extra: sample code to enable travelling between 2 disconnected countries Indonesia <-> Australia
            // Allow to travel from Indonesia -> Australia
            Country    indonesia     = map.GetCountry("Indonesia");
            List <int> newNeighbours = new List <int> (indonesia.neighbours);

            newNeighbours.Add(map.GetCountryIndex("Australia"));
            map.GetCountry("Indonesia").neighbours = newNeighbours.ToArray();
            // Do the same in reverse direction Australia -> Indonesia
            Country australia = map.GetCountry("Australia");

            newNeighbours = new List <int> (australia.neighbours);
            newNeighbours.Add(map.GetCountryIndex("Indonesia"));
            map.GetCountry("Australia").neighbours = newNeighbours.ToArray();
        }
        public void DrawOutline()
        {
            Region area = null;

            Country[] mapCountries = new Country[3];
            mapCountries[0] = map.GetCountry("France");
            mapCountries[1] = map.GetCountry("Spain");
            mapCountries[2] = map.GetCountry("Germany");
            foreach (Country cData in mapCountries)
            {
                if (area == null)
                {
                    area = cData.mainRegion;
                }
                else
                {
                    area = map.RegionMerge(area, cData.mainRegion);
                }
            }

            if (outline != null)
            {
                Destroy(outline);
            }

            outline = map.DrawRegionOutline("PlayerRealm", area, borderTexture, 1f, Color.blue);
        }
        void ShowTooltip(float x, float y)
        {
            Country country = map.GetCountry(new Vector2(x, y));

            if (country == null)
            {
                infoPanel.anchoredPosition = new Vector2(-300, 0);
                return;
            }
            infoPanelCountryName.text      = country.name;
            infoPanelCountryResources.text = "$" + country.attrib ["Resources"];
            infoPanel.anchoredPosition     = Input.mousePosition + new Vector3(10, -30);
        }
        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);
        }
示例#5
0
        void Start()
        {
            map = WMSK.instance;

            int    USAIndex = map.GetCountryIndex("United States of America");
            Region region   = map.GetCountry(USAIndex).mainRegion;

            map.RegionGenerateExtrudeGameObject("Extruded USA", region, 1f, Color.gray);

            map.FlyToCountry(USAIndex, 4f, 0.2f);
        }
示例#6
0
        void ColorizeFrance()
        {
            Country country = map.GetCountry("France");

            for (int p = 0; p < country.provinces.Length; p++)
            {
                Color color         = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
                int   provinceIndex = map.GetProvinceIndex(country.provinces[p]);
                map.ToggleProvinceSurface(provinceIndex, true, color);
            }
        }
示例#7
0
 void HandleOnCountryEnter(int destinationCountryIndex, int regionIndex)
 {
     if (startCountryIndex >= 0 && startCountryIndex != destinationCountryIndex)
     {
         // Clear existing path
         Refresh();
         // Find a country path between starting country and destination country
         List <int> countriesInPath = map.FindRoute(map.GetCountry(startCountryIndex), map.GetCountry(destinationCountryIndex));
         // If a path has been found, paint it!
         if (countriesInPath != null)
         {
             countriesInPath.ForEach(countryIndex => map.ToggleCountrySurface(countryIndex, true, Color.grey));
         }
         else
         {
             // Otherwise, show it's not possible to reach that country.
             Debug.Log(map.countries[destinationCountryIndex].name + " is not reachable from " + map.countries[startCountryIndex].name + "! You may need to adjust the neighbours property of some countries to enable crossing.");
         }
     }
 }
示例#8
0
        IEnumerator LaunchMissile(float delay, string countryOrigin, string countryDest, Color color)
        {
            float start = Time.time;

            while (Time.time - start < delay)
            {
                yield return(null);
            }

            // Initiates line animation
            int cityOrigin = map.GetCityIndexRandom(map.GetCountry(countryOrigin));
            int cityDest   = map.GetCityIndexRandom(map.GetCountry(countryDest));

            if (cityOrigin < 0 || cityDest < 0)
            {
                yield break;
            }

            Vector2            origin    = map.cities [cityOrigin].unity2DLocation;
            Vector2            dest      = map.cities [cityDest].unity2DLocation;
            float              elevation = 1f;
            float              width     = 0.25f;
            LineMarkerAnimator lma       = map.AddLine(origin, dest, color, elevation, width);

            lma.dashInterval          = 0.0003f;
            lma.dashAnimationDuration = 0.5f;
            lma.drawingDuration       = 4f;
            lma.autoFadeAfter         = 1f;

            // Add flashing target
            GameObject sprite = Instantiate(target) as GameObject;

            sprite.GetComponent <SpriteRenderer> ().material.color = color * 0.9f;
            map.AddMarker2DSprite(sprite, dest, 0.003f);
            MarkerBlinker.AddTo(sprite, 4, 0.1f, 0.5f, true);

            // Triggers explosion
            StartCoroutine(AddCircleExplosion(4f, dest, Color.yellow));
        }
示例#9
0
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

            // UI Setup - non-important, only for this demo
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.white;

            map.OnCountryClick += (int countryIndex, int regionIndex, int buttonIndex) => {
                map.RegionSetCustomElevation(map.GetCountry(countryIndex).regions, 0.7f);
            };
        }
示例#10
0
 public WorldMapStrategyKit.Country GenericToMapCountry(WPM.Country country)
 {
     return(_WMSK.GetCountry(_WMSK.GetCountryIndex(country.name)));
 }
示例#11
0
        /// <summary>
        /// Creates a tank instance and adds it to specified city
        /// </summary>
        void DropTankOnCity()
        {
            // Get a random big city
            int cityIndex = map.GetCityIndex("Paris", "France");

            // Get city location
            Vector2 cityPosition = map.cities [cityIndex].unity2DLocation;

            if (tank != null)
            {
                DestroyImmediate(tank.gameObject);
            }
            tank = DropTankOnPosition(cityPosition);

            // Zoom into tank
            map.FlyToLocation(cityPosition, 2.0f, 0.15f);

            // Enable move on click in this demo
            enableAddTowerOnClick = false;
            enableClickToMoveShip = false;
            enableClickToMoveTank = true;

            // Finally, signal me when tank starts and stops
            tank.OnMoveStart     += (thisTank) => Debug.Log("Tank has starting moving to " + thisTank.destination + " location.");
            tank.OnMoveEnd       += (thisTank) => Debug.Log("Tank has stopped at " + thisTank.currentMap2DLocation + " location.");
            tank.OnCountryEnter  += (thisTank) => Debug.Log("Tank has entered country " + map.GetCountry(thisTank.currentMap2DLocation).name + ".");
            tank.OnProvinceEnter += (thisTank) => Debug.Log("Tank has entered province " + map.GetProvince(thisTank.currentMap2DLocation).name + ".");
        }
示例#12
0
        // Use this for initialization
        void Start()
        {
            State.turn = 1;
            State.setGamePhase(MyEnum.GamePhase.adminstration);
            map = WMSK.instance;

            SelfProvinceGUI.SetActive(false);
            OtherProvinceGUI.SetActive(false);

            // WMSKMiniMap.Show();


            string nationsPath = Application.dataPath +
                                 "/StreamingAssets/Scenarios/DefaultFictional/Nations";
            string provincesPath = Application.dataPath +
                                   "/StreamingAssets/Scenarios/DefaultFictional/Provinces";



            string[] provFiles = Directory.GetFiles(provincesPath, "*.json");
            //foreach (string file in System.IO.Directory.GetFiles(provincesPath))
            foreach (string file in provFiles)
            {
                string dataAsJson = File.ReadAllText(file);

                //  Debug.Log(dataAsJson);
                //  assemblyCsharp.Province province = assemblyCsharp.Province.CreateFromJSON(dataAsJson);
                //assemblyCsharp.Province province = new assemblyCsharp.Province();
                // assemblyCsharp.Province newProvince = JsonUtility.FromJson<assemblyCsharp.Province>(dataAsJson);
                var newProvince = Newtonsoft.Json.JsonConvert.DeserializeObject <assemblyCsharp.Province>(dataAsJson);
                provinces.Add(newProvince.getIndex(), newProvince);
                // Debug.Log("Culture: " + newProvince.getCulture());

                map.GetProvince(newProvince.getIndex()).name        = newProvince.getProvName();
                map.GetProvince(newProvince.getIndex()).customLabel = newProvince.getProvName();
            }

            string[] nationFiles = Directory.GetFiles(nationsPath, "*.json");

            foreach (string file in nationFiles)
            {
                string dataAsJson = File.ReadAllText(file);
                //   Debug.Log(dataAsJson);
                var newNation = Newtonsoft.Json.JsonConvert.DeserializeObject <assemblyCsharp.Nation>(dataAsJson);
                //   Nation newNation = JsonUtility.FromJson<Nation>(dataAsJson);

                nations.Add(newNation.getIndex(), newNation);
                map.GetCountry(newNation.getIndex()).name = newNation.getNationName();
                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));
                newNation.setColor(color);
                // map.ToggleCountrySurface(newNation.getIndex(), true, color);
                map.GetCountry(newNation.getIndex()).customLabel = newNation.getNationName();
                map.CountryRename("Country" + newNation.getIndex(), newNation.getNationName());
            }

            map.Redraw();

            for (int k = 0; k < map.countries.Length; k++)
            {
                //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));
                Color color = nations[k].getColor();
                //    Debug.Log("f**k: " + k + " " + color);

                map.ToggleCountrySurface(k, true, color);
            }

            float       left   = 0.78f;
            float       top    = 0.02f;
            float       width  = 0.2f;
            float       height = 0.2f;
            Vector4     normalizedScreenRect = new Vector4(left, top, width, height);
            WMSKMiniMap minimap = WMSKMiniMap.Show(normalizedScreenRect);

            // string path = Application.dataPath + "Alpha9.png";
            minimap.map.earthStyle = EARTH_STYLE.SolidColor;
            //  string absoluteImagePath = Path.Combine(Application.streamingAssetsPath, "ScenarioOne/Alpha9.png");

            //Texture2D  miniMapTexture = loadSprite(path);
            Texture2D miniMapTexture = Resources.Load("AlphaPrime.png", typeof(Texture2D)) as Texture2D;

            minimap.map.earthTexture = miniMapTexture;
            minimap.map.fillColor    = Color.blue;
            minimap.map.earthColor   = Color.blue;

            minimap.duration  = 1.5f;
            minimap.zoomLevel = 0.4f;


            for (int countryIndex = 0; countryIndex < map.countries.Length; countryIndex++)
            {
                Color color = nations[countryIndex].getColor();
                minimap.map.ToggleCountrySurface(countryIndex, true, color);
            }


            Dictionary <int, string> majorNations = NationData.majorDict;
            Dictionary <int, string> minorNations = NationData.minorDict;
            Dictionary <int, string> uncivNations = NationData.uncivDict;

            map.showProvinceNames = true;

            WorldMapStrategyKit.Province prov = map.GetProvince(45);
            Vector2 position = prov.center;

            //  Vector2 position = map.GetProvince(45, 20).center;


            army      = PlaceArmy(position);
            army.name = "first unit";
            army.GetComponent <ArmyController>().army = army;

            Vector2 position2 = map.GetProvince(32).center;

            Nation humanPlayer = nations[16];

            humanPlayer.SetHuman(true);

            //


            //Ship Click

            /*  map.OnClick += (float x, float y, int buttonIndex) => {
             *    Vector2 shipPosition = new Vector2(x, y);
             *    byte byteValue1= 0;
             *
             *    map.waterMaskLevel = byteValue1;
             *    if (map.ContainsWater(shipPosition))
             *    {
             *        Debug.Log("Water!");
             *
             *    }
             *    else
             *    {
             *        Debug.Log("Land!");
             *    }
             *    if (map.GetProvince(shipPosition) == null)
             *    {
             *        ship.MoveTo(shipPosition, 0.1f);
             *    }
             *
             * }; */


            // LaunchShip();

            //Show resources of each provinces
            //  ShowProvinceResources();

            map.OnClick += (float x, float y, int buttonIndex) =>
            {
                Vector2 provincePosition = new Vector2(x, y);
                int     clickedIndex     = map.GetProvinceIndex(provincePosition);
                assemblyCsharp.Province clickedProvince = provinces[clickedIndex];
            };
        }
示例#13
0
        void Start()
        {
            WMSK map = WMSK.instance;

            // ***********************************************************************
            // Adding custom attributes to a country (same for provinces, cities, ...)
            // ***********************************************************************

            Country canada = map.GetCountry("Canada");

            canada.attrib ["Language"]         = "French";                                              // Add language as a custom attribute
            canada.attrib ["ConstitutionDate"] = new DateTime(1867, 7, 1);                              // Add the date of British North America Act, 1867
            canada.attrib ["AreaKm2"]          = 9984670;                                               // Add the land area in km2

            // List example
            List <int> values = new List <int> (10);

            for (int j = 0; j < 10; j++)
            {
                values.Add(j);
            }
            canada.attrib ["List"] = JSONObject.FromArray(values);

            // ******************************************************
            // Obtain attributes and print them out over the console.
            // ******************************************************

            Debug.Log("Language = " + canada.attrib ["Language"]);
            Debug.Log("Constitution Date = " + canada.attrib ["ConstitutionDate"].d);                   // Note the use of .d to force cast the internal number representation to DateTime
            Debug.Log("Area in km2 = " + canada.attrib ["AreaKm2"]);
            Debug.Log("List = " + canada.attrib ["List"]);

            // *********************************************************
            // Now, look up by attribute example using lambda expression
            // *********************************************************

            List <Country> countries = map.GetCountries(
                (attrib) => "French".Equals(attrib ["Language"]) && attrib ["AreaKm2"] > 1000000
                );

            Debug.Log("Matches found = " + countries.Count);
            foreach (Country c in countries)
            {
                Debug.Log("Match: " + c.name);
            }

            // *****************************************************************
            // Export/import individual country attributes in JSON format sample
            // *****************************************************************

            string json = canada.attrib.Print();                // Get raw jSON

            Debug.Log(json);

            canada.attrib = new JSONObject(json);               // Import from raw jSON
            int keyCount = canada.attrib.keys.Count;

            Debug.Log("Imported JSON has " + keyCount + " keys.");
            for (int k = 0; k < keyCount; k++)
            {
                Debug.Log("Key " + (k + 1) + ": " + canada.attrib.keys [k] + " = " + canada.attrib [k]);
            }

            // *****************************************************************
            // Finally, export all countries attributes in one single JSON file
            // *****************************************************************

            string jsonCountries = map.GetCountriesAttributes(true);                    // get the complete json for all countries with attributes

            Debug.Log(jsonCountries);

            canada.attrib = null;
            map.SetCountriesAttributes(jsonCountries);                                                  // parse the jsonCountries string (expects a jSON compliant string) and loads the attributes
            Debug.Log("Canada's attributes restored: Lang = " + canada.attrib ["Language"] + ", Date = " + canada.attrib ["ConstitutionDate"].d + ", Area = " + canada.attrib ["AreaKm2"]);
        }