public static HexEdge GetNearestEdge(Vector3 coords) { HexCorner corner = HexCorner.GetNearestCorner(coords); HexCorner[] neighbors = HexCorner.GetNeighbors(corner); float[] distances = new float[neighbors.Length]; for (int i = 0; i < neighbors.Length; i++) { distances[i] = Vector3.Distance(coords, neighbors[i].ToLocalCoords()); } return(new HexEdge(corner, neighbors[Array.IndexOf(distances, Mathf.Min(distances))])); }
private void Build(HexCorner corner) { //dont add duplicates if (Neighbors.ContainsKey(corner)) { return; } HexCorner[] possibleNeighbors = HexCorner.GetNeighbors(corner); HexCorner[] validNeighbors = possibleNeighbors.Where((HexCorner val) => { return(!IsOutOfRange(val)); }).ToArray(); Neighbors.Add(corner, validNeighbors); for (int i = 0; i < validNeighbors.Length; i++) { Build(validNeighbors[i]); } }