/// Returns all tiles within a certain hex-grid manhattan distance of the origin public static List <Vector2Int> GetAllWithinManhattanRange(Vector3Int origin, int range, bool includeSelf) { //Performance Tip if this turns out to be a bottleNeck in your games Performance: precalculate all the offsets for range 1,2,3,4,5,6... etc just once and store them in a list or dictionary //Don't optimize it when not needed though, keeping things simple should be the priority List <Vector2Int> positions = new List <Vector2Int>(); int minX = origin.x - range; int maxX = origin.x + range; int minY = origin.y - range; int maxY = origin.y + range; for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { int z = -x - y; if (Mathf.Abs(z - origin.z) > range) { continue; } positions.Add(HexConversions.CubeCoordToOffsetCoord(new Vector3Int(x, y, z))); } } if (!includeSelf) { positions.Remove(HexConversions.CubeCoordToOffsetCoord(origin)); } return(positions); }
public void HightlightCurrentHex(Color color) { Vector2Int hexPos = HexConversions.CubeCoordToOffsetCoord(curPosition); Tile tile = (Tile)gameManager.map.Tiles[hexPos.x, hexPos.y].GetComponent(typeof(Tile)); tile.HightlightHex(color); }
public Tile GetTileData(Vector3Int coord) { Vector2Int offsetCoord = HexConversions.CubeCoordToOffsetCoord(coord); return((Tile)Tiles[offsetCoord.x, offsetCoord.y].GetComponent(typeof(Tile))); }