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();
        }
        public void DemoRoute()
        {
            Vector2 cityStartRoute = map.GetCity("Madrid", "Spain").unity2DLocation;
            Vector2 cityEndRoute   = map.GetCity("Rome", "Italy").unity2DLocation;
            Cell    startCell      = map.GetCell(cityStartRoute);
            Cell    endCell        = map.GetCell(cityEndRoute);

            List <int> cellIndices = map.FindRoute(startCell, endCell, TERRAIN_CAPABILITY.OnlyGround);

            // Highlight cells in path
            map.CellBlink(cellIndices, Color.yellow, 4f);

            // Closer look
            map.FlyToLocation(cityStartRoute, 0.5f, 0.2f);
        }
Beispiel #3
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();
        }
Beispiel #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.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;
        }
Beispiel #5
0
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

            // Focus on middle ground
            Vector2 koreaPos = map.GetCity("Pyongyang", "North Korea").unity2DLocation;
            Vector2 japanPos = map.GetCity("Tokyo", "Japan").unity2DLocation;
            Vector2 midPos   = (koreaPos + japanPos) / 2f;

            map.FlyToLocation(midPos, 3f, 0.08f);

            // Launch 5 waves of attacks and counter-attacks
            for (int wave = 0; wave < 5; wave++)
            {
                StartCoroutine(War(wave * 3));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Checks if tank is near Paris. Then moves it to Moscow. Otherwise, moves it back to Paris.
        /// </summary>
        void MoveTankAndFollow()
        {
            string destinationCity, destinationCountry;

            if (tank == null)
            {
                DropTankOnCity();
            }

            // Gets position of Paris in map
            Vector2 parisPosition = map.GetCity("Paris", "France").unity2DLocation;

            // Is the tank nearby (less than 50 km)? Then set destination to Moscow, otherwize Paris again
            if (map.calc.Distance(tank.currentMap2DLocation, parisPosition) < 50000)
            {
                destinationCity    = "Moscow";
                destinationCountry = "Russia";
            }
            else
            {
                destinationCity    = "Paris";
                destinationCountry = "France";
            }

            // Get position of destination
            Vector2 destination = map.GetCity(destinationCity, destinationCountry).unity2DLocation;

            Debug.Log(destinationCity + " " + destinationCountry + " " + destination);

            // For this movement, we will move the tank following a straight line
            tank.terrainCapability = TERRAIN_CAPABILITY.Any;

            // Move the tank to the new position with smooth ease
            tank.easeType = EASE_TYPE.SmoothStep;

            // Use a close zoom during follow - either current zoom level or 0.1f maximum so tank is watched closely
            tank.follow          = true;
            tank.followZoomLevel = Mathf.Min(0.1f, map.GetZoomLevel());

            // Move it!
            tank.MoveTo(destination, 4.0f);
        }
        void BuildRoad()
        {
            int city1Index = map.GetCityIndex("Berlin", "Germany");
            int city2Index = map.GetCityIndex("Paris", "France");
            // Get starting and end cell
            Cell cell1 = map.GetCell(map.GetCity(city1Index).unity2DLocation);
            Cell cell2 = map.GetCell(map.GetCity(city2Index).unity2DLocation);
            // Get the path
            List <int> cellIndices = map.FindRoute(cell1, cell2, TERRAIN_CAPABILITY.OnlyGround);

            if (cellIndices == null)
            {
                return;
            }

            // Highlight road cells
            map.CellBlink(cellIndices, new Color(1, 1, 0.5f, 0.5f), 1f);

            // Get coordinates for the path
            int positionsCount = cellIndices.Count;

            Vector2[] positions = new Vector2[positionsCount];
            for (int k = 0; k < positionsCount; k++)
            {
                positions [k] = map.cells [cellIndices [k]].center;
            }

            // Build a road along the map coordinates
            LineMarkerAnimator lma = map.AddLine(positions, Color.white, 0, 0.1f);

            lma.lineMaterial.mainTexture      = roadTexture;
            lma.lineMaterial.mainTextureScale = new Vector2(8f, 1f);

            // Apply reduced costs to hex sides crossed by the road
            for (int k = 1; k < positionsCount; k++)
            {
                map.PathFindingCellSetSideCost(cellIndices [k - 1], cellIndices [k], 1);
            }
        }
        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);
        }
Beispiel #9
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()
        {
            // 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"); };
        }
Beispiel #11
0
        void OnCityEnter(int cityIndex)
        {
            City city = map.GetCity(cityIndex);

            ShowCityInfo(city);
        }