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

            GUI.Label(new Rect(10, 15, 500, 30), "Wrap horizontally enabled to allow infinite horizontal scrolling. Move ship around.");

            // 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, 40, 130, 30), "  Locate Ship", buttonStyle))
            {
                map.FlyToLocation(ship.currentMap2DLocation, 2f, 0.05f);
            }
            if (GUI.Button(new Rect(10, 80, 130, 30), "  Reposition Ship", buttonStyle))
            {
                LaunchShip();
            }
            if (GUI.Button(new Rect(10, 120, 130, 30), "  Clear Trail", buttonStyle))
            {
                if (trailParent != null)
                {
                    Destroy(trailParent);
                }
            }
        }
        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);
        }
Ejemplo n.º 3
0
        void FixedUpdate()
        {
            mouseEventProcessedThisFrame = false;

            if (isMoving)
            {
                if (onFixedMoveEnabled)
                {
                    // Updates game object position
                    if (isAffectedByBuoyancy)
                    {
                        transform.rotation   = lastComputedRotation;
                        isAffectedByBuoyancy = false;
                    }

                    MoveGameObject();
                    UpdateTransformAndVisibility();
                    CheckEvents();

                    // Follow object?
                    if (_follow)
                    {
                        float   t         = Lerp.EaseOut((map.time - followStartTime) / followDuration);
                        float   zoomLevel = Mathf.Lerp(followStartZoomLevel, followZoomLevel, t);
                        Vector2 loc       = Vector2.Lerp(followStart2DLocation, _currentMap2DLocation, t);
                        map.FlyToLocation(loc, 0, zoomLevel);
                    }
                }
            }
            else
            {
                CheckBuoyancyEffect();
            }
        }
Ejemplo n.º 4
0
 void OnEnable()
 {
     map = GetComponent <WMSK>();
     map.showCountryNames       = false;
     map.showCities             = false;
     map.showProvinces          = false;
     map.showFrontiers          = false;
     map.showLatitudeLines      = false;
     map.showOutline            = false;
     map.showLongitudeLines     = false;
     map.frontiersDetail        = FRONTIERS_DETAIL.Low;
     map.earthStyle             = EARTH_STYLE.Alternate1;
     map.allowUserDrag          = false;
     map.allowUserKeys          = false;
     map.allowUserZoom          = false;
     map.enableCountryHighlight = false;
     map.zoomMaxDistance        = 0;
     map.zoomMinDistance        = 0;
     map.cursorColor            = new Color(0.6f, 0.8f, 1f, 1f);
     map.cursorAlwaysVisible    = false;
     map.respectOtherUI         = false;
     map.OnClick += (float x, float y, int buttonIndex) => {
         if (primaryMap == null)
         {
             primaryMap = WMSK.instance;
         }
         if (primaryMap != null)
         {
             primaryMap.FlyToLocation(new Vector2(x, y), duration, zoomLevel);
         }
     };
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Illustrates how to add custom markers over the map using the AddMarker API.
        /// In this example a building prefab is added to a random city (see comments for other options).
        /// </summary>
        void AddMarkerOnRandomCity()
        {
            // Every marker is put on a spherical-coordinate (assuming a radius = 0.5 and relative center at zero position)
            Vector2 planeLocation;

            // Add a marker on a random city
            City city = map.cities[Random.Range(0, map.cities.Count)];

            planeLocation = city.unity2DLocation;

            // or... choose a city by its name:
//		int cityIndex = map.GetCityIndex("Moscow");
//		planeLocation = map.cities[cityIndex].unity2DLocation;

            // or... use the centroid of a country
//		int countryIndex = map.GetCountryIndex("Greece");
//		planeLocation = map.countries[countryIndex].center;

            // or... use a custom location lat/lon. Example put the building over New York:
//		map.calc.fromLatDec = 40.71f;	// 40.71 decimal degrees north
//		map.calc.fromLonDec = -74.00f;	// 74.00 decimal degrees to the west
//		map.calc.fromUnit = UNIT_TYPE.DecimalDegrees;
//		map.calc.Convert();
//		planeLocation = map.calc.toPlaneLocation;

            // Send the prefab to the AddMarker API setting a scale of 0.1f (this depends on your marker scales)
            GameObject star = Instantiate(Resources.Load <GameObject>("Sprites/StarSprite"));

            map.AddMarker2DSprite(star, planeLocation, 0.02f, true);

            // Add an optional click handler for this sprite
            MarkerClickHandler handler = star.GetComponent <MarkerClickHandler>();

            handler.OnMarkerMouseDown  += (buttonIndex => Debug.Log("Click on sprite with button " + buttonIndex + "!"));
            handler.OnMarkerMouseEnter += () => Debug.Log("Pointer is on sprite!");
            handler.OnMarkerMouseExit  += () => Debug.Log("Pointer exits sprite!");

            // Fly to the destination and see the building created
            map.FlyToLocation(planeLocation);

            // Optionally add a blinking effect to the marker
            MarkerBlinker.AddTo(star, 3, 0.2f);
        }
        void FlyZoomOut()
        {
            tank.follow = false;
            map.FlyToLocation(tank.currentMap2DLocation, 4f, 0.2f);

            // Before switching view mode, initiates fade to smooth transition effect
            Invoke("StartFade", 0.4f);

            // After 1 second of flight, switch to normal mode. You could also check current zoomLevel in the Update() method and change accordingly.
            Invoke("DisableViewport", 1f);
        }
Ejemplo n.º 8
0
        void LaunchShip()
        {
            int     cityIndex     = 0;
            Vector2 cityPosition  = map.cities[cityIndex].unity2DLocation;
            Vector2 waterPosition = cityPosition;

            // Create ship
            ship = DropShipOnPosition(waterPosition);
            // Fly to the location of ship with provided zoom level
            map.FlyToLocation(waterPosition, 2.0f, 0.1f);
        }
Ejemplo n.º 9
0
        void ShowBorderPoints()
        {
            int            cadizIndex   = map.GetProvinceIndex("Spain", "Cádiz");
            int            sevilleIndex = map.GetProvinceIndex("Spain", "Sevilla");
            List <Vector2> points       = map.GetProvinceBorderPoints(cadizIndex, sevilleIndex);

            points.ForEach((point) => AddBallAtPosition(point));
            if (points.Count > 0)
            {
                map.FlyToLocation(points[0], 2, 0.01f);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a tower instance and adds it to the map at a random city
        /// </summary>
        void AddRandomTower()
        {
            // Get a random big city
            int cityIndex = -1;

            do
            {
                cityIndex = Random.Range(0, map.cities.Length);
            } while (map.cities [cityIndex].population < 10000);

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

            // Create tower and add it to the map
            AddTowerAtPosition(cityPosition.x, cityPosition.y);

            // Fly to the location with provided zoom level
            map.FlyToLocation(cityPosition, 2.0f, 0.1f);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Illustrates how to add custom markers over the map using the AddMarker API.
        /// In this example a building prefab is added to a random city (see comments for other options).
        /// </summary>
        void AddMarkerSpriteOnRandomCity()
        {
            // Every marker is put on a plane-coordinate (in the range of -0.5..0.5 on both x and y)
            Vector2 planeLocation;

            // Add a marker on a random city
            City city = map.cities[Random.Range(0, map.cities.Length)];

            planeLocation = city.unity2DLocation;

            // or... choose a city by its name:
            //		int cityIndex = map.GetCityIndex("Moscow");
            //		planeLocation = map.cities[cityIndex].unity2DLocation;

            // or... use the centroid of a country
            //		int countryIndex = map.GetCountryIndex("Greece");
            //		planeLocation = map.countries[countryIndex].center;

            // or... use a custom location lat/lon. Example put the building over New York:
            //		map.calc.fromLatDec = 40.71f;	// 40.71 decimal degrees north
            //		map.calc.fromLonDec = -74.00f;	// 74.00 decimal degrees to the west
            //		map.calc.fromUnit = UNIT_TYPE.DecimalDegrees;
            //		map.calc.Convert();
            //		planeLocation = map.calc.toPlaneLocation;

            // Send the prefab to the AddMarker API setting a scale of 0.02f (this depends on your marker scales)
            GameObject star = Instantiate(Resources.Load <GameObject>("Sprites/StarSprite"));

            map.AddMarker2DSprite(star, planeLocation, 0.02f);

            // Fly to the destination and see the building created
            map.FlyToLocation(planeLocation);

            // Optionally add a blinking effect to the marker
            MarkerBlinker.AddTo(star, 3, 0.2f);
        }
Ejemplo n.º 12
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));
            }
        }
        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);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a tank instance and adds it to specified city
        /// </summary>
        void DropTankOnCity()
        {
            // Get a random big city
            int cityIndex = map.GetCityIndex("Lhasa", "China");

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

            if (tank != null)
            {
                DestroyImmediate(tank);
            }
            GameObject tankGO = Instantiate(Resources.Load <GameObject>("Tank/CompleteTank"));

            tank                   = tankGO.WMSK_MoveTo(cityPosition);
            tank.type              = (int)UNIT_TYPE.TANK;
            tank.autoRotation      = true;
            tank.terrainCapability = TERRAIN_CAPABILITY.OnlyGround;

            // Zoom into tank
            map.FlyToLocation(cityPosition, 2.0f, 0.15f);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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 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"); };
        }