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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a line to the 2D map with options (returns the line gameobject).
        /// </summary>
        /// <param name="points">Sequence of points for the line</param>
        /// <param name="Color">line color</param>
        /// <param name="arcElevation">arc elevation (-0.5 .. 0.5)</param>
        public LineMarkerAnimator AddLine(Vector2[] points, Color color, float arcElevation, float lineWidth)
        {
            LineMarkerAnimator lma = AddLine(points, markerLineMat, arcElevation, lineWidth);

            lma.color = color;
            return(lma);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Example of how to add custom lines to the map
        /// Similar to the AddMarker functionality, you need two spherical coordinates and then call AddLine
        /// </summary>
        void AddTrajectories()
        {
            map.SetZoomLevel(1f, 1f);

            // In this example we will add random lines from 5 cities to another cities (see AddMaker example above for other options to get locations)

            for (int line = 0; line < 5; line++)
            {
                // Get two random cities
                int city1 = Random.Range(0, map.cities.Length);
                int city2 = Random.Range(0, map.cities.Length);

                // Get their sphere-coordinates
                Vector2 start = map.cities[city1].unity2DLocation;
                Vector2 end   = map.cities[city2].unity2DLocation;

                // Add line with random color, speeds and elevation
                Color color            = new Color(Random.Range(0.5f, 1), Random.Range(0.5f, 1), Random.Range(0.5f, 1));
                float elevation        = Random.Range(0, 0.1f);
                float lineWidth        = 0.1f;
                LineMarkerAnimator lma = map.AddLine(start, end, color, elevation, lineWidth);

                // Additional line effects
                lma.drawingDuration = 4.0f;
                lma.autoFadeAfter   = 2.0f; // line stays for 2 seconds, then fades out - set this to zero to avoid line removal

                // Add custom end caps
                lma.startCap       = lineStartCap;
                lma.startCapOffset = 0.5f;
                lma.startCapScale  = new Vector3(1f, 1f, 1f);
                lma.endCap         = lineEndCap;
                lma.endCapOffset   = 0.5f;
                lma.endCapScale    = new Vector3(1f, 1f, 1f);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Used when show Route Path toggle is checked
        /// </summary>
        void UpdateRoutePathLine(float x, float y)
        {
            if (pathLine != null)               // remove existing line
            {
                DestroyImmediate(pathLine.gameObject);
            }

            // Find a route for this tank to destination
            Vector2        destination = new Vector2(x, y);
            List <Vector2> route       = tank.FindRoute(destination);

            if (route == null)
            {
                // Draw a straight red line if no route is available
                pathLine = map.AddLine(tank.currentMap2DLocation, destination, Color.red, pathArcElevation, pathLineWidth);
            }
            else
            {
                pathLine = map.AddLine(route.ToArray(), Color.yellow, pathArcElevation, pathLineWidth);
            }
            pathLine.drawingDuration       = pathDrawingDuration;
            pathLine.dashInterval          = pathDashInterval;
            pathLine.dashAnimationDuration = pathDashAnimationDuration;

            UpdateCircle(destination);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Used when show Linear Path toggle is checked
        /// </summary>
        void UpdateLinearPathLine(float x, float y)
        {
            if (pathLine != null)               // remove existing line
            {
                DestroyImmediate(pathLine.gameObject);
            }

            // destination of linear path
            Vector2 destination = new Vector2(x, y);

            // optionally choose a material for the line (you may simply pass a color instead)
            Material lineMat = pathArcElevation > 0 ? lineMaterialAerial : lineMaterialGround;

            // draw the line
            pathLine = map.AddLine(tank.currentMap2DLocation, destination, lineMat, pathArcElevation, pathLineWidth);
            pathLine.drawingDuration       = pathDrawingDuration;
            pathLine.dashInterval          = pathDashInterval;
            pathLine.dashAnimationDuration = pathDashAnimationDuration;
            if (showEndCap)
            {
                pathLine.endCap              = endCapSprite;
                pathLine.endCapMaterial      = endCapMaterial;
                pathLine.endCapScale         = new Vector3(1f, 1f, 2.5f);
                pathLine.endCapOffset        = 4f;
                pathLine.endCapFlipDirection = true;
            }

            UpdateCircle(destination);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Example of how to add custom lines to the map
        /// Similar to the AddMarker functionality, you need two spherical coordinates and then call AddLine
        /// </summary>
        void AddTrajectories()
        {
            // In this example we will add random lines from 5 cities to another cities (see AddMaker example above for other options to get locations)
            map.SetZoomLevel(1f);

            for (int line = 0; line < 5; line++)
            {
                // Get two random cities
                int city1 = Random.Range(0, map.cities.Count);
                int city2 = Random.Range(0, map.cities.Count);

                // Get their sphere-coordinates
                Vector2 start = map.cities[city1].unity2DLocation;
                Vector2 end   = map.cities[city2].unity2DLocation;

                // Add line with random color, speeds and elevation
                Color color     = new Color(Random.Range(0f, 0.5f), Random.Range(0f, 0.5f), Random.Range(0f, 0.5f));
                float elevation = Random.Range(0.1f, 5f);
                float lineWidth = 0.9f;

                LineMarkerAnimator lma = map.AddLine(start, end, color, elevation, lineWidth);
                lma.drawingDuration = 4.0f;
                lma.autoFadeAfter   = 2.0f;               // line stays for 2 seconds, then fades out - set this to zero to avoid line removal
                if (UnityEngine.Random.value > 0.5f)      // make it a dash line
                {
                    lma.drawingDuration       = 2.0f;
                    lma.dashInterval          = 0.01f;
                    lma.dashAnimationDuration = 0.25f;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a line to the 2D map with options (returns the line gameobject).
        /// </summary>
        /// <param name="start">starting location on the plane (-0.5, -0.5)-(0.5,0.5)</param>
        /// <param name="end">end location on the plane (-0.5, -0.5)-(0.5,0.5)</param>
        /// <param name="arcElevation">arc elevation (-0.5 .. 0.5)</param>
        public LineMarkerAnimator AddLine(Vector2 start, Vector2 end, Color color, float arcElevation, float lineWidth)
        {
            Vector2[]          path = new Vector2[] { start, end };
            LineMarkerAnimator lma  = AddLine(path, markerLineMat, arcElevation, lineWidth);

            lma.color = color;
            return(lma);
        }
Ejemplo n.º 8
0
        IEnumerator TransferProvinces()
        {
            // Reset map
            map.ReloadData();
            map.Redraw();

            // Transfer some German provinces to Poland
            int countryIndex = map.GetCountryIndex("Poland");

            // Step 1: Focus on area of provinces
            map.showProvinces    = true;
            map.drawAllProvinces = true;
            map.FlyToProvince("Germany", "Brandenburg", 1f, 0.04f);
            yield return(new WaitForSeconds(1f));

            // Step 2: Mark provinces
            string[] provincesToTransfer = new string[] {
                "Brandenburg",
                "Mecklenburg-Vorpommern",
                "Sachsen-Anhalt",
                "Sachsen",
                "Thüringen"
            };
            foreach (string provinceName in provincesToTransfer)
            {
                int provinceIndex = map.GetProvinceIndex("Germany", provinceName);
                map.BlinkProvince(provinceIndex, Color.white, Color.red, 2f, 0.15f);
                LineMarkerAnimator lma = map.AddLine(new Vector2[] {
                    map.provinces [provinceIndex].center,
                    map.countries [countryIndex].center
                }, Color.yellow, 1f, 0.15f);
                lma.dashInterval          = 0.0001f;
                lma.dashAnimationDuration = 0.3f;
                lma.drawingDuration       = 2.5f;
                lma.autoFadeAfter         = 0.5f;
                lma.fadeOutDuration       = 0f;
            }
            yield return(new WaitForSeconds(3f));

            // Step 3: transfer some German provinces to Poland
            foreach (string provinceName in provincesToTransfer)
            {
                Province province = map.GetProvince(provinceName, "Germany");
                if (!map.CountryTransferProvinceRegion(countryIndex, province.mainRegion, false))
                {
                    Debug.LogError("Could not transfer province " + provinceName + " to Poland.");
                }
            }
            map.Redraw();

            // End

            map.FlyToCountry("Poland", 1f, 0.04f);
            map.BlinkCountry("Poland", Color.white, Color.green, 2f, 0.15f);

            Debug.Log("Done.");
        }
        IEnumerator TransferCountry()
        {
            // Reset map
            map.ReloadData();
            map.Redraw();

            // Countries in action
            string targetCountry      = "Czech Republic";
            string sourceCountry      = "Slovakia";
            int    targetCountryIndex = map.GetCountryIndex(targetCountry);
            int    sourceCountryIndex = map.GetCountryIndex(sourceCountry);

            if (sourceCountryIndex < 0 || targetCountryIndex < 0)
            {
                Debug.Log("Countries not found.");
                yield break;
            }

            // Step 1: Mark countries
            map.FlyToCountry(sourceCountry, 1f, 0.05f);
            map.BlinkCountry(sourceCountry, Color.white, Color.red, 2f, 0.15f);
            yield return(new WaitForSeconds(1f));

            // Step 2: Add animated line
            LineMarkerAnimator lma = map.AddLine(new Vector2[]
            {
                map.countries[sourceCountryIndex].center,
                map.countries[targetCountryIndex].center
            }, Color.yellow, 2f, 0.15f);

            lma.dashInterval          = 0.0005f;
            lma.dashAnimationDuration = 0.3f;
            lma.drawingDuration       = 2.5f;
            lma.autoFadeAfter         = 0.5f;
            lma.fadeOutDuration       = 0f;
            yield return(new WaitForSeconds(3f));

            // Step 3: Transfer Slovakia to Czech Republic
            Region sourceRegion = map.GetCountry("Slovakia").mainRegion;

            if (!map.CountryTransferCountryRegion(targetCountryIndex, sourceRegion, false))
            {
                Debug.LogError("Country could not be transferred.");
                yield break;
            }

            // Step 4: rename Czech Republic to Czechoslovakia
            if (!map.CountryRename("Czech Republic", "Czechoslovakia"))
            {
                Debug.LogError("Country could not be renamed.");
            }

            // Step 5: refresh any change on screen and highlight the new country
            map.Redraw();
            map.BlinkCountry("Czechoslovakia", Color.white, Color.blue, 2f, 0.15f);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a line to the 2D map from the center of one given cell to another (returns the line gameobject).
        /// </summary>
        /// <param name="points">Sequence of points for the line</param>
        /// <param name="side">the side of the hexagonal cell</param>
        /// <param name="color">line color</param>
        /// <param name="lineWidth">line width</param>
        public LineMarkerAnimator AddLine(int cellIndex1, int cellIndex2, Color color, float lineWidth)
        {
            LineMarkerAnimator lma = AddLine(cellIndex1, cellIndex2, markerLineMat, lineWidth);

            if (lma != null)
            {
                lma.color = color;
            }
            return(lma);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds a line to the 2D map from the center of one given cell to another (returns the line gameobject).
        /// </summary>
        /// <param name="points">Sequence of points for the line</param>
        /// <param name="side">the side of the hexagonal cell</param>
        /// <param name="material">line material</param>
        /// <param name="lineWidth">line width</param>
        public LineMarkerAnimator AddLine(int cellIndex1, int cellIndex2, Material material, float lineWidth)
        {
            if (cells == null || cellIndex1 < 0 || cellIndex1 >= cells.Length || cellIndex2 < 0 || cellIndex2 >= cells.Length)
            {
                return(null);
            }
            Vector2[] points = new Vector2[2];
            points[0] = cells[cellIndex1].center;
            points[1] = cells[cellIndex2].center;
            LineMarkerAnimator lma = AddLine(points, material, 0, lineWidth);

            lma.numPoints = 2;
            return(lma);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds a line to the 2D map over a Cell edge with options (returns the line gameobject).
        /// </summary>
        /// <param name="points">Sequence of points for the line</param>
        /// <param name="side">the side of the hexagonal cell</param>
        /// <param name="material">line material</param>
        /// <param name="lineWidth">line width</param>
        public LineMarkerAnimator AddLine(int cellIndex, CELL_SIDE side, Material material, float lineWidth)
        {
            if (cells == null || cellIndex < 0 || cellIndex >= cells.Length)
            {
                return(null);
            }
            Vector2[] points = new Vector2[2];
            Cell      cell   = cells[cellIndex];

            switch (side)
            {
            case CELL_SIDE.TopLeft:
                points[0] = cell.points[0];
                points[1] = cell.points[1];
                break;

            case CELL_SIDE.Top:
                points[0] = cell.points[1];
                points[1] = cell.points[2];
                break;

            case CELL_SIDE.TopRight:
                points[0] = cell.points[2];
                points[1] = cell.points[3];
                break;

            case CELL_SIDE.BottomRight:
                points[0] = cell.points[3];
                points[1] = cell.points[4];
                break;

            case CELL_SIDE.Bottom:
                points[0] = cell.points[4];
                points[1] = cell.points[5];
                break;

            case CELL_SIDE.BottomLeft:
                points[0] = cell.points[5];
                points[1] = cell.points[0];
                break;
            }
            LineMarkerAnimator lma = AddLine(points, material, 0, lineWidth);

            lma.numPoints = 2;
            return(lma);
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Adds a line to the 2D map with options (returns the line gameobject).
        /// </summary>
        /// <param name="points">Sequence of points for the line</param>
        /// <param name="lineMaterial">line material</param>
        /// <param name="arcElevation">arc elevation (-0.5 .. 0.5)</param>
        public LineMarkerAnimator AddLine(Vector2[] points, Material lineMaterial, float arcElevation, float lineWidth)
        {
            CheckMarkersLayer();
            GameObject newLine = new GameObject("MarkerLine");

            newLine.layer = gameObject.layer;
            bool usesRenderViewport = renderViewportIsEnabled && arcElevation > 0;

            if (!usesRenderViewport)
            {
                newLine.transform.SetParent(markersLayer.transform, false);
            }
            LineMarkerAnimator lma = newLine.AddComponent <LineMarkerAnimator>();

            lma.map          = this;
            lma.path         = points;
            lma.color        = Color.white;
            lma.arcElevation = arcElevation;
            lma.lineWidth    = lineWidth;
            lma.lineMaterial = lineMaterial;
            return(lma);
        }
        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);
            }
        }