Exemplo n.º 1
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;
            labelStyleShadow                   = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor  = Color.black;
            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>("GUI/thumb");
            sliderThumbStyle.overflow          = new RectOffset(0, 0, 8, 0);
            sliderThumbStyle.fixedWidth        = 20.0f;
            sliderThumbStyle.fixedHeight       = 12.0f;

            // Prepare line texture
            lineMaterialAerial = Instantiate(Resources.Load <Material>("PathLine/aerialPath"));
            lineMaterialGround = Instantiate(Resources.Load <Material>("PathLine/groundPath"));

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

            // plug our mouse click listener - it will be used to move the tank to target destination
            map.OnClick += (float x, float y, int buttonIndex) => {
                if (enableClickToMoveTank)
                {
                    MoveTankWithPathFinding(new Vector2(x, y));
                }
            };

            // plug our mouse move listener - it received the x,y map position of the mouse
            map.OnMouseMove += (float x, float y) => {
                // while tank is moving avoid showing paths
                if (tank.isMoving)
                {
                    return;
                }
                // if show linear path is enabled, then just show a straight (or curved line if arc elevation is specified) from tank to destination
                if (showLinearPath)
                {
                    UpdateLinearPathLine(x, y);
                }
                else
                {
                    // show route path is enabled, then we'll compute the path and draw a line that pass through those points
                    UpdateRoutePathLine(x, y);
                }
            };

            map.CenterMap();

            // Drop the tank on the Tibet
            DropTankOnCity();
        }
Exemplo n.º 2
0
 void Start()
 {
     map = WMSK.instance;
 }
 void Start()
 {
     map          = WMSK.instance;
     map.OnClick += MapClickEvent;
 }
Exemplo n.º 4
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;
            labelStyleShadow                   = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor  = Color.black;
            buttonStyle                        = new GUIStyle(labelStyle);
            buttonStyle.alignment              = TextAnchor.MiddleLeft;
            buttonStyle.normal.background      = Texture2D.whiteTexture;
            buttonStyle.normal.textColor       = Color.white;
            colorPicker                        = gameObject.GetComponent <ColorPicker>();
            sliderStyle                        = new GUIStyle();
            sliderStyle.normal.background      = Texture2D.whiteTexture;
            sliderStyle.fixedHeight            = 4.0f;
            sliderThumbStyle                   = new GUIStyle();
            sliderThumbStyle.normal.background = Resources.Load <Texture2D>("GUI/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);

            /* Register events: this is optionally but allows your scripts to be informed instantly as the mouse enters or exits a country, province or city */
            map.OnCellEnter += (int cellIndex) => Debug.Log("Entered cell #" + cellIndex + " at row " + map.cells[cellIndex].row + ", column " + map.cells[cellIndex].column);
            map.OnCellExit  += (int cellIndex) => Debug.Log("Exited cell #" + cellIndex + " at row " + map.cells[cellIndex].row + ", column " + map.cells[cellIndex].column);
            map.OnCellClick += (int cellIndex, int buttonIndex) => {
                int row = map.cells[cellIndex].row;
                int col = map.cells[cellIndex].column;
                Debug.Log("Clicked cell #" + cellIndex + " at row " + row + ", column " + col + ", center = " + map.cells[cellIndex].center);
                switch (mode)
                {
                case ACTION_MODE.Blink:
                case ACTION_MODE.FadeOut:
                case ACTION_MODE.Flash:
                    AnimateCells(row, col);
                    break;

                case ACTION_MODE.Paint:
                    PaintCurrentCell();
                    break;

                case ACTION_MODE.FadeCountry:
                    PaintCurrentCountry();
                    break;
                }
            };

            map.SetZoomLevel(0.3f);
            map.showGrid = true;
            cellsCount   = map.gridColumns;

            // Simple benchmark
            //			Debug.Log (System.DateTime.Now.ToString("hh:mm:ss.fff tt"));
            //			map.gridMinDistance = 0;
            //			map.gridMaxDistance = 100;
            //			map.gridRows = 128;
            //			map.gridColumns = 256;
            //			Debug.Log (System.DateTime.Now.ToString("hh:mm:ss.fff tt"));
            //			for (int k=0;k<map.cells.Length;k++) {
            //				map.ToggleCellSurface(k, true, Color.red);
            //			}
            //			Debug.Log (System.DateTime.Now.ToString("hh:mm:ss.fff tt"));
        }
Exemplo n.º 5
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];
            };
        }
Exemplo n.º 6
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"]);
        }