public Hex GetNeighbour(HexDirection direction) { if ((int)direction > HexDirectionUtility.DirectionCount()) { direction = (HexDirection)((int)direction & HexDirectionUtility.DirectionCount()); } if ((int)direction < 0) { direction = (HexDirection)(HexDirectionUtility.DirectionCount() & (int)direction); } return(neighbours[(int)direction]); }
private void TriangulateBorder(ref List <Hex> a_area, ref List <Hex> a_exclude) { bool process = false; // Process each hex in area by checking if one of their neighbours are outside the area, and add them to the border if true foreach (Hex tile in a_area) { process = a_exclude != null ? !a_exclude.Contains(tile) : true; // Don't process tiles in the excluded list if (process) { foreach (Hex neighbour in tile.Neighbours) { // check if the neighbour is outside of the area, if it's on the excluded list then don't check (useful when a unit is blocking a hex but shouldn’t have a border) if (!a_area.Contains(neighbour) && (a_exclude != null && !a_exclude.Contains(neighbour))) { border.Add(tile); break; // break because if one neighbour is outside the area then it's a border hex } } } } // process each hex in border and add the points that border the outside of the area foreach (Hex tile in border) { for (int i = 0; i < tile.Neighbours.Count; i++) { HexDirection direction = HexDirectionUtility.DirectionFromNeighbour(tile, tile.Neighbours[i]); Vector3 centre = tile.transform.localPosition; process = a_exclude != null ? !a_exclude.Contains(tile.Neighbours[i]) : true; if (!a_area.Contains(tile.Neighbours[i]) && process) { AddTriangle( centre + HexUtility.GetFirstCorner(direction), centre + HexUtility.GetSecondCorner(direction), centre + HexUtility.GetFirstCorner(direction) * inverseThickness ); AddTriangleUV( centre + HexUtility.GetFirstCorner(direction), centre + HexUtility.GetSecondCorner(direction), centre + HexUtility.GetFirstCorner(direction) * inverseThickness ); AddTriangle( centre + HexUtility.GetSecondCorner(direction) * inverseThickness, centre + HexUtility.GetFirstCorner(direction) * inverseThickness, centre + HexUtility.GetSecondCorner(direction) ); AddTriangleUV( centre + HexUtility.GetSecondCorner(direction) * inverseThickness, centre + HexUtility.GetFirstCorner(direction) * inverseThickness, centre + HexUtility.GetSecondCorner(direction) ); } else if (border.Contains(tile.Neighbours[i])) { int closestCorner = ClosestToOutside(tile, centre + HexUtility.GetFirstCorner(direction), centre + HexUtility.GetSecondCorner(direction), ref a_area, ref a_exclude); if (closestCorner == 2) { AddTriangle( centre + HexUtility.GetSecondCorner(direction), centre + HexUtility.GetSecondCorner(direction) * inverseThickness, centre + HexUtility.GetSecondCorner(direction) + (HexUtility.GetFirstCorner(direction) - HexUtility.GetSecondCorner(direction)) * borderThickness ); AddTriangleUV( centre + HexUtility.GetSecondCorner(direction), centre + HexUtility.GetSecondCorner(direction) * inverseThickness, centre + HexUtility.GetSecondCorner(direction) + (HexUtility.GetFirstCorner(direction) - HexUtility.GetSecondCorner(direction)) * borderThickness ); } else if (closestCorner == 1) { AddTriangle( centre + HexUtility.GetFirstCorner(direction), centre + HexUtility.GetFirstCorner(direction) + (HexUtility.GetSecondCorner(direction) - HexUtility.GetFirstCorner(direction)) * borderThickness, centre + HexUtility.GetFirstCorner(direction) * inverseThickness ); AddTriangleUV( centre + HexUtility.GetFirstCorner(direction), centre + HexUtility.GetFirstCorner(direction) + (HexUtility.GetSecondCorner(direction) - HexUtility.GetFirstCorner(direction)) * borderThickness, centre + HexUtility.GetFirstCorner(direction) * inverseThickness ); } } } } }