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); }
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(); }
void HandleOnCellEnter(int destinationCellIndex) { if (startCellIndex >= 0 && startCellIndex != destinationCellIndex) { // Clear existing path ClearPreviousPath(); // Find a cell path between starting cell and destination cell, only over ground, at any altitude and with a maximum traversing cost of tank.maxSearchCost path = map.FindRoute(map.GetCell(startCellIndex), map.GetCell(destinationCellIndex), out pathCost, tank.terrainCapability, tank.maxSearchCost); // If a path has been found, paint it! if (path != null) { ShowPathAndCosts(path); } else { // Otherwise, show it's not possible to reach that cell. Debug.Log("Cell #" + destinationCellIndex + " is not reachable from cell #" + startCellIndex); } } }