コード例 #1
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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #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);
            }
        }
コード例 #4
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;
                }
            }
        }
コード例 #5
0
        void OnGUI()
        {
            // Do autoresizing of GUI layer
            GUIResizer.AutoResize();

            string msg = "Select destination cell!";

            GUI.Label(new Rect(11, 11, 300, 20), msg, labelStyleShadow);
            GUI.Label(new Rect(10, 10, 300, 20), msg, labelStyle);

            if (map.cellHighlightedIndex >= 0)
            {
                msg = "Current cell: " + map.cellHighlightedIndex;
                GUI.Label(new Rect(11, 31, 300, 20), msg, labelStyleShadow);
                GUI.Label(new Rect(10, 30, 300, 20), msg, labelStyle);
            }

            if (GUI.Button(new Rect(10, 60, 100, 20), "Draw Barrier", buttonStyle))
            {
                // Very basic sample of how to draw some lines to create a visual barrier over the edges of some hexagonal cells
                map.AddLine(101133, CELL_SIDE.Top, Color.cyan, 0.1f);
                map.AddLine(101134, CELL_SIDE.TopLeft, Color.cyan, 0.1f);
                map.AddLine(101134, CELL_SIDE.Top, Color.cyan, 0.1f);
                map.AddLine(101134, CELL_SIDE.TopRight, Color.cyan, 0.1f);
                map.AddLine(101135, CELL_SIDE.Top, Color.cyan, 0.1f);
                map.AddLine(101136, CELL_SIDE.TopLeft, Color.cyan, 0.1f);
                map.AddLine(101136, CELL_SIDE.Top, Color.cyan, 0.1f);
                map.AddLine(101136, CELL_SIDE.TopRight, Color.cyan, 0.1f);
                // Set crossing costs for barrier for each edge. Note that here I'm using the hard coded cell numbers for this example. If you change the number of rows or columns of the grid
                // this will obviously fail.
                int cost = 10000;
                map.PathFindingCellSetSideCost(101133, 101645, cost);
                map.PathFindingCellSetSideCost(101134, 101645, cost);
                map.PathFindingCellSetSideCost(101134, 101646, cost);
                map.PathFindingCellSetSideCost(101134, 101647, cost);
                map.PathFindingCellSetSideCost(101135, 101647, cost);
                map.PathFindingCellSetSideCost(101136, 101647, cost);
                map.PathFindingCellSetSideCost(101136, 101648, cost);
                map.PathFindingCellSetSideCost(101136, 101649, cost);
            }

            GUI.Label(new Rect(10, 100, 250, 30), "Non colored terrain cost: 1 point");
            GUI.Label(new Rect(10, 120, 250, 30), "Green movement cost: 2 point");
            GUI.Label(new Rect(10, 140, 250, 30), "Gray movement cost: 3 points");
            GUI.Label(new Rect(10, 160, 250, 30), "Press R to show movement range.");

            if (tank.maxSearchCost > 5 || ((int)Time.time) % 2 != 0)
            {
                GUI.Label(new Rect(10, 180, 250, 30), "Tank move points: " + tank.maxSearchCost);
            }
            if (tank.maxSearchCost < 5)
            {
                GUI.Label(new Rect(10, 200, 250, 30), "Press M to add more move points.");
            }
        }
コード例 #6
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.");
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        void ShowPath()
        {
            map.pathFindingEnableCustomRouteMatrix = true;
            map.PathFindingCustomRouteMatrixReset();
            map.OnPathFindingCrossPosition += Map_OnPathFindingCrossPosition;

            Vector2 fromLocation = map.GetCountry("Russia").center;
            Vector2 toLocation   = map.GetCountry("Czech Republic").center;

            List <Vector2> path = map.FindRoute(fromLocation, toLocation, TERRAIN_CAPABILITY.OnlyGround, maxSearchCost: 1000000, maxSearchSteps: 100000);

            if (path != null)
            {
                map.AddLine(path.ToArray(), Color.red, 0, 0.5f);
            }
        }
コード例 #9
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));
        }