public void MakeMesh() { hexHeight = Vector3.Distance( tilemap.CellToWorld(HexTools.GetAdjacentTileOffset(Vector3Int.zero, Cardinality.N)), tilemap.CellToWorld(new Vector3Int(0, 0, 0))); float diagonalDist = Vector3.Distance( tilemap.CellToWorld(Vector3Int.zero), tilemap.CellToWorld(HexTools.GetAdjacentTileOffset(Vector3Int.zero, Cardinality.NE))); hexWidth = Mathf.Sqrt(diagonalDist * diagonalDist - Mathf.Pow(hexHeight * .5f, 2)) * 4 / 3; tilemap.ClearAllTiles(); var tiles = HexTools.GetSpiral(Vector3Int.zero, mapRadius); TileBase[] tileArray = new TileBase[tiles.Count]; for (int index = 0; index < tiles.Count; index++) { tileArray[index] = testTile; } tilemap.SetTiles(tiles.ToArray(), tileArray); if (mapRadius == 0) { mapRadius = 1; } float[,] noiseMap = Noise.GenerateNoiseMap(4 * mapRadius * 2, 3 * mapRadius * 2, noiseSettings, Vector2.zero); MeshIt(tiles.ToArray(), noiseMap); }
void Update() { Vector3 mousepos = Input.mousePosition; Ray ray = cam.ScreenPointToRay(mousepos); Plane plane = new Plane(Vector3.back, Vector3.zero); if (plane.Raycast(ray, out float hitDist)) { Vector3 worldpoint = ray.GetPoint(hitDist); Vector3Int tilepoint = tilemap.WorldToCell(worldpoint); TerrainTile tile = GetTile(tilepoint); if (startTile != null) { foreach (Vector3Int lineTile in lastLine) { tilemap.SetColor(lineTile, Color.white); } lastLine.Clear(); foreach (Vector3Int radiusTile in lastRadius) { tilemap.SetColor(radiusTile, Color.white); } lastRadius.Clear(); foreach (Vector3Int ringTile in lastRing) { tilemap.SetColor(ringTile, Color.white); } lastRing.Clear(); if (Input.GetMouseButtonUp(0)) { startTile = null; } else { int n = HexTools.DistanceInTiles(startTile.coordinates, tilepoint); List <Vector3Int> radius = HexTools.GetSpiral(startTile.coordinates, n); //HexTools.GetTilesInRange(startTile.coordinates, n); List <Vector3Int> line = HexTools.GetLine(startTile.coordinates, tilepoint); List <Vector3Int> ring = HexTools.GetRing(startTile.coordinates, n); foreach (Vector3Int radiusTile in radius) { tilemap.SetColor(radiusTile, Color.yellow); } foreach (Vector3Int radiusTile in ring) { tilemap.SetColor(radiusTile, Color.red); } foreach (Vector3Int lineTile in line) { tilemap.SetColor(lineTile, Color.magenta); } lastLine = line; lastRadius = radius; lastRing = ring; } } if (tile == null && Input.GetMouseButtonDown(0)) { RevealArea(tilepoint, revealRadius); } else { if (tile != null) { if (Input.GetMouseButtonDown(0)) { Debug.Log("World: " + worldpoint + " Coords: " + tilepoint); startTile = tile; } } else { if (Input.GetMouseButtonDown(0)) { Debug.Log("Null Tilepoint: " + tilepoint); } } } } }