void UpdateRectangle(bool finishSelection)
        {
            if (map == null)
            {
                return;
            }

            Vector2 center = (startPos + endPos) * 0.5f;
            Vector2 scale  = new Vector2(Mathf.Abs(endPos.x - startPos.x), Mathf.Abs(endPos.y - startPos.y));

            map.AddMarker2DSprite(gameObject, center, scale);
            Vector2[] points = new Vector2[5];
            points [0] = center - scale * 0.5f;
            points [1] = points [0] + Misc.Vector2right * scale.x;
            points [2] = points [1] + Misc.Vector2up * scale.y;
            points [3] = points [2] - Misc.Vector2right * scale.x;
            points [4] = points [3] - Misc.Vector2up * scale.y;
            if (lines != null)
            {
                DestroyImmediate(lines.gameObject);
            }
            lines = map.AddLine(points, lineColor, 0f, lineWidth);
            lines.dashInterval          = 0.001f;
            lines.dashAnimationDuration = 0.2f;
            if (callback != null)
            {
                callback(new Rect(center - scale * 0.5f, scale), finishSelection);
            }
        }
        /// <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);
        }
Example #3
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));
        }
Example #4
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);
        }