Exemple #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();
        }
        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;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);
        }
Exemple #3
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;

            // 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.OnCityEnter     += (int cityIndex) => Debug.Log("Entered city " + map.cities[cityIndex].name);
            map.OnCityExit      += (int cityIndex) => Debug.Log("Exited city " + map.cities[cityIndex].name);
            map.OnCityClick     += (int cityIndex, int buttonIndex) => Debug.Log("Clicked city " + map.cities[cityIndex].name);
            map.OnProvinceEnter += (int provinceIndex, int regionIndex) => Debug.Log("Entered province " + map.provinces[provinceIndex].name);
            map.OnProvinceExit  += (int provinceIndex, int regionIndex) => Debug.Log("Exited province " + map.provinces[provinceIndex].name);
            map.OnProvinceClick += (int provinceIndex, int regionIndex, int buttonIndex) => Debug.Log("Clicked province " + map.provinces[provinceIndex].name);

            //map.FlyToCountry("Spain", 3, 0.05f);
        }
Exemple #4
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;
            buttonStyle                       = new GUIStyle(labelStyle);
            buttonStyle.alignment             = TextAnchor.MiddleCenter;
            buttonStyle.normal.background     = Texture2D.whiteTexture;
            buttonStyle.normal.textColor      = Color.black;

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

            // WMSK setup
            map              = WMSK.instance;
            map.OnCellClick += HandleOnCellClick;
            map.OnCellEnter += HandleOnCellEnter;

            // Focus on Berlin
            City city = map.GetCity("Berlin", "Germany");

            map.FlyToCity(city, 1f, 0.1f);

            // Creates a tank and positions it on the center of the hexagonal cell which contains Berlin
            Cell startCell = map.GetCell(city.unity2DLocation);

            DropTankOnPosition(startCell.center);
            startCellIndex = map.GetCellIndex(startCell);

            // Paint some country costs
            PaintCountries();
        }
Exemple #5
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.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

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

            // Create tank
            Vector2 parisLocation = map.GetCity("Paris", "France").unity2DLocation;

            tank1 = DropTankOnPosition(parisLocation);

            // Fly to Paris
            map.FlyToLocation(parisLocation, 2f, 0.1f);

            // Listen to events
            map.OnClick += MapClickHandler;

            // Disable right-click centers since we'll be using right mouse button to fire
            map.centerOnRightClick = false;
        }
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

            // Get a reference to the viewport gameobject (we'll enable/disable it when changing modes)
            viewport = GameObject.Find("Viewport");

            // Get the material of the fade plane
            fadePlane    = Camera.main.transform.Find("FadePlane").gameObject;
            fadeMaterial = fadePlane.GetComponent <Renderer>().sharedMaterial;

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

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

            map.CenterMap();

            // Create tank
            kathmanduLocation = map.GetCity("Kathmandu", "Nepal").unity2DLocation;
            beijingLocation   = map.GetCity("Beijing", "China").unity2DLocation;
            tank = DropTankOnPosition(kathmanduLocation);

            // Start movement
            tank.MoveTo(beijingLocation, 0.1f);
            tank.OnMoveEnd += (anim) => SwitchDestination();
        }
Exemple #7
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;

            map.FlyToCountry("Spain", 0, 0.17f);
        }
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

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

            // Get list of European countries
            europeanCountries = new List <Country>();
            for (int k = 0; k < map.countries.Length; k++)
            {
                Country country = map.countries[k];
                if (country.continent.Equals("Europe"))
                {
                    europeanCountries.Add(country);
                    // Distribute countries between 2 players
                    if (country.center.x < 0.04f)
                    {
                        country.attrib["player"] = 1;
                    }
                    else
                    {
                        country.attrib["player"] = 2;
                    }
                }
            }

            // Colors
            player1Color = new Color(1, 0.5f, 0, 0.65f);
            player2Color = new Color(0, 0.5f, 1, 0.65f);

            // Setup map rect
            map.windowRect = new Rect(-0.0587777f, 0.1964018f, 0.1939751f, 0.1939751f);
            map.SetZoomLevel(0.1939751f);
            map.CenterMap();

            // Paint countries
            PaintCountries();

            // Drop our tester tank
            DropTankOnCity();

            // On map click listener
            map.OnClick += (float x, float y, int buttonIndex) => {
                if (enableToggleOwnership)
                {
                    ChangeCountryOwnerShip(x, y);
                }
                else if (enableClickToMoveTank)
                {
                    MoveTankWithPathFinding(new Vector2(x, y));
                }
            };

            // Enable custom cost path finding matrix (we'll setup this matrix when moving the unit)
            map.pathFindingEnableCustomRouteMatrix = true;
            UpdatePathFindingMatrixCost();
        }
Exemple #9
0
        void Start()
        {
            // 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;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);
        }
Exemple #10
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.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

            // 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.OnCityEnter += OnCityEnter;
            map.OnCityExit  += OnCityExit;
        }
Exemple #11
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.OnCityEnter     += (int cityIndex) => Debug.Log("Entered city " + map.cities[cityIndex].name);
            map.OnCityExit      += (int cityIndex) => Debug.Log("Exited city " + map.cities[cityIndex].name);
            map.OnCityClick     += (int cityIndex, int buttonIndex) => Debug.Log("Clicked city " + map.cities[cityIndex].name);
            map.OnCountryEnter  += (int countryIndex, int regionIndex) => Debug.Log("Entered country " + map.countries[countryIndex].name);
            map.OnCountryExit   += (int countryIndex, int regionIndex) => Debug.Log("Exited country " + map.countries[countryIndex].name);
            map.OnCountryClick  += (int countryIndex, int regionIndex, int buttonIndex) => Debug.Log("Clicked country " + map.countries[countryIndex].name);
            map.OnProvinceEnter += (int provinceIndex, int regionIndex) => Debug.Log("Entered province " + map.provinces[provinceIndex].name);
            map.OnProvinceExit  += (int provinceIndex, int regionIndex) => Debug.Log("Exited province " + map.provinces[provinceIndex].name);
            map.OnProvinceClick += (int provinceIndex, int regionIndex, int buttonIndex) => Debug.Log("Clicked province " + map.provinces[provinceIndex].name);

            map.OnDragStart += () => {
                Debug.Log("Drag starts.");
            };
            map.OnDragEnd += () => {
                Debug.Log("Drag ends.");
            };
        }
Exemple #12
0
        void Start()
        {
            map = WMSK.instance;

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

            // setup GUI styles - only for the demo
            buttonStyle                   = new GUIStyle();
            buttonStyle.alignment         = TextAnchor.MiddleCenter;
            buttonStyle.normal.background = Texture2D.whiteTexture;
            buttonStyle.normal.textColor  = Color.black;

                        #if UNITY_EDITOR
            EditorUtility.DisplayDialog("Load/Save Demo", "In this demo scene, a map change is simulated (North America is collapsed into one single country), then saved and loaded.", "Ok");
                        #endif
        }
        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.OnProvinceClick += HandleOnProvinceClick;
            map.OnProvinceEnter += HandleOnProvinceEnter;
        }
        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;

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

            // Listen to map events
            map.OnClick += (float x, float y, int buttonIndex) => {
                if (autoExpand)
                {
                    return;
                }
                if (buttonIndex == 0)
                {
                    int countryIndex = map.GetCountryIndex(new Vector2(x, y));
                    SelectPrincipalCountry(countryIndex);
                }
                else
                {
                    Region region = map.GetCountryRegion(new Vector2(x, y));
                    ExpandCountry(region);
                }
            };
        }
Exemple #15
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;

            // 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.OnCityEnter     += (int cityIndex) => Debug.Log("Entered city " + map.cities[cityIndex].name);
            map.OnCityExit      += (int cityIndex) => Debug.Log("Exited city " + map.cities[cityIndex].name);
            map.OnCityClick     += (int cityIndex, int buttonIndex) => Debug.Log("Clicked city " + map.cities[cityIndex].name);
            map.OnCountryEnter  += (int countryIndex, int regionIndex) => Debug.Log("Entered country " + map.countries[countryIndex].name);
            map.OnCountryExit   += (int countryIndex, int regionIndex) => Debug.Log("Exited country " + map.countries[countryIndex].name);
            map.OnCountryClick  += (int countryIndex, int regionIndex, int buttonIndex) => Debug.Log("Clicked country " + map.countries[countryIndex].name);
            map.OnProvinceEnter += (int provinceIndex, int regionIndex) => Debug.Log("Entered province " + map.provinces[provinceIndex].name);
            map.OnProvinceExit  += (int provinceIndex, int regionIndex) => Debug.Log("Exited province " + map.provinces[provinceIndex].name);
            map.OnProvinceClick += (int provinceIndex, int regionIndex, int buttonIndex) => Debug.Log("Clicked province " + map.provinces[provinceIndex].name);
            map.OnClick         += (float x, float y, int buttonIndex) => MakeClick(x, y);
            map.CenterMap();

            map.gridColumns = 300;
            map.gridRows    = 300;
            map.showGrid    = true;

            // Example: how to clear a group of cells inside a country
//												map.OnClick += (float x, float y, int buttonIndex) => {
//																List<int> cells = map.GetCellsInCountry(map.GetCountryIndex("Spain"));
//																map.FogOfWarSetCells(cells, 0.1f);
//												};
        }
        void Start()
        {
            // setup GUI resizer - only for the demo
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.white;
            GUIResizer.Init(800, 500);

            // Get a reference to the World Map API:
            map = WMSK.instance;
            map.renderViewportGOAutoScaleMax = 4f;
            map.renderViewportGOAutoScaleMin = 1f;

            // Create tanks
            const int   NUM_TANKS = 5;
            const float DISTANCE  = 0.004f;

            tanks = new List <GameObjectAnimator> (NUM_TANKS);
            Vector2 locationBase = map.GetCity("Paris", "France").unity2DLocation;

            for (int k = 0; k < NUM_TANKS; k++)
            {
                // initial position for tank
                Vector2 pos   = locationBase + new Vector2(Random.value - 0.5f, Random.value - 0.5f).normalized *DISTANCE;
                int     tries = 0;
                // is another tank on this position?
                while (tries++ < 100 && map.VGOGet(pos, 0.005f) != null)
                {
                    pos = locationBase + new Vector2(Random.value - 0.5f, Random.value - 0.5f).normalized *Random.value *DISTANCE;
                }
                // drop tank there
                GameObjectAnimator tank = DropTankOnPosition(pos);
                tanks.Add(tank);
            }
            selectedUnits = new List <GameObjectAnimator> ();

            // Fly to Paris
            map.FlyToLocation(locationBase, 2f, 0.05f);
        }
Exemple #17
0
        float timeOfDay = 0.0f;         // in hours (0-23.99)

        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;

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

            map.CenterMap();

            // Instantiate game object and position it instantly over the city
            GameObject tower    = Instantiate(Resources.Load <GameObject> ("Tower/Tower"));
            Vector2    position = map.GetCity("Lhasa", "China").unity2DLocation;

            tower.WMSK_MoveTo(position);

            // Zoom in
            map.FlyToLocation(position, 1f, 0.1f);
        }
        void Start()
        {
            // UI Setup - non-important, only for this demo
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

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

            // Real useful code:

            // 1) Get a reference to the WMSK API
            map = WMSK.instance;

            // 2) Remove any existing map; to prevent loading geodata files at start, check the toggle DontLoadGeodataAtStart in WMSK inspector
            map.ClearAll();

            // 3) Create country based on cells defined by columns and rows
            int[,] cells = new int[, ]
            {
                { 20, 10 },
                { 21, 10 },
                { 20, 11 },
                { 21, 11 }
            };
            countryIndex = CreateHexCountry("My country", cells);

            // Focus on country
            map.FlyToCountry(countryIndex, 2f, 0.2f);

            // Optional: Fill the new country with a color
            map.ToggleCountrySurface(countryIndex, true, countryColor);

            // Optional: allow country expansion using click on other cells
            map.OnCellClick += CellClicked;
        }
Exemple #19
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;

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

            map.OnClick += (float x, float y, int buttonIndex) => {
                if (enableAddTowerOnClick)
                {
                    AddTowerAtPosition(x, y);
                }
                else if (enableClickToMoveTank)
                {
                    MoveTankWithPathFinding(new Vector2(x, y));
                }
                else if (enableClickToMoveShip && ship != null)
                {
                    // as ship has terrainCapability set to Water the MoveTo() method will use path finding to route the ship to destination.
                    MoveShipToDestination(new Vector2(x, y), 0.1f);
                }
            };

            map.CenterMap();
        }
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

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

            // setup GUI styles
            labelStyle                    = new GUIStyle();
            labelStyle.alignment          = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor   = Color.white;
            buttonStyle                   = new GUIStyle(labelStyle);
            buttonStyle.alignment         = TextAnchor.MiddleLeft;
            buttonStyle.normal.background = Texture2D.whiteTexture;
            buttonStyle.normal.textColor  = Color.white;

            // Listen to click event to move the ship around
            map.OnClick += (float x, float y, int buttonIndex) => {
                ship.MoveTo(new Vector2(x, y), 0.1f);
            };

            LaunchShip();
        }
        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.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

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

            // Create two tanks
            Vector2 parisLocation = map.GetCity("Paris", "France").unity2DLocation;

            tank1      = DropTankOnPosition(parisLocation);
            tank1.name = "French Tank";
            Vector2 madridLocation = map.GetCity("Madrid", "Spain").unity2DLocation;

            tank2      = DropTankOnPosition(madridLocation);
            tank2.name = "Spanish Tank";

            // Fly to a mid-point between Paris and Madrid
            Vector2 midPoint = (parisLocation + madridLocation) * 0.5f;

            map.FlyToLocation(midPoint, 2f, 0.1f);

            // Listen to unit-level events (if you need unit-level events...)
            tank1.OnPointerEnter += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank1.name + " mouse enter event.");
            tank1.OnPointerExit  += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank1.name + " mouse exit.");
            tank1.OnPointerUp    += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank1.name + " mouse button up.");
            tank1.OnPointerDown  += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank1.name + " mouse button down.");

            tank2.OnPointerEnter += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank2.name + " mouse enter event.");
            tank2.OnPointerExit  += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank2.name + " mouse exit.");
            tank2.OnPointerUp    += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank2.name + " mouse button up.");
            tank2.OnPointerDown  += (GameObjectAnimator anim) => Debug.Log("UNIT EVENT: " + tank2.name + " mouse button down.");

            // Listen to global Vieport GameObject (VGO) events (... better and simple approach)

            map.OnVGOPointerDown = delegate(GameObjectAnimator obj) {
                Debug.Log("GLOBAL EVENT: Left button pressed on " + obj.name);
                ColorTankMouseDown(obj);
            };
            map.OnVGOPointerUp = delegate(GameObjectAnimator obj) {
                Debug.Log("GLOBAL EVENT: Left button released on " + obj.name);
                ColorTankMouseUp(obj);
            };

            map.OnVGOPointerRightDown = delegate(GameObjectAnimator obj) {
                Debug.Log("GLOBAL EVENT: Right button pressed on " + obj.name);
                ColorTankMouseDown(obj);
            };
            map.OnVGOPointerRightUp = delegate(GameObjectAnimator obj) {
                Debug.Log("GLOBAL EVENT: Right button released on " + obj.name);
                ColorTankMouseUp(obj);
            };

            map.OnVGOPointerEnter = delegate(GameObjectAnimator obj) {
                Debug.Log("GLOBAL EVENT: Mouse entered " + obj.name);
                ColorTankHover(obj);
            };
            map.OnVGOPointerExit = delegate(GameObjectAnimator obj) {
                Debug.Log("GLOBAL EVENT: Mouse exited " + obj.name);
                RestoreTankColor(obj);
            };

            map.OnClick += (float x, float y, int buttonIndex) => { Debug.Log("Map Clicked"); };
        }
        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();
        }