// public bool Position_Coord_Radius(Vector3 p, ref Coord v, ref ushort height) { if (!Position_Coord(p, ref v, ref height)) { height = (ushort)((p.y + fHeightFix - bound_min.y) / fYLayerHeight); Coord[] neighbour = v.Neighbour(); ushort[] harray = new ushort[6]; int count = 0; for (int i = 0; i < neighbour.Length; i++) { v = neighbour[i]; v.y = i; if (!IsCoordValid(v)) { continue; } ushort temp = 0; if (Coord_Height(ref v, ref temp)) { harray[count] = temp; count++; } } if (count == 0) { return(false); } else { ushort temp = harray[0]; int min = Mathf.Abs(height - temp); for (int i = 1; i < count; i++) { int val = Mathf.Abs(height - harray[i]); if (val < min) { min = val; temp = harray[i]; } } height = temp; return(true); } return(false); } return(true); }
// void SortbyHeight() // { // int OneLayerTileCount = xTileCount * zTileCount; // for (int z = 0; z < zTileCount; z++) // { // for (int x = 0; x < xTileCount; x++) // { // int idxLow = z * xTileCount + x; // int idxHigh = OneLayerTileCount + idxLow; // // if (tileData[idxHigh] != null) // { // tileData[idxLow].CompareSwap(tileData[idxHigh]); // } // } // } // } // 构建边缘权重aa public void BuildHexagonWeight() { for (int z = 0; z < zCount; z++) { for (int x = 0; x < xCount; x++) { Coord v = new Coord(); v.x = x; v.z = z; v.y = 0; int layerCount = GetTileLayerCount(v); for (int layer = 0; layer < layerCount; layer++) { v.y = layer; ushort current = GetHeight(v); if (current == 0) { continue; } int currentHeight = current & Tile.HeightMask; int neighbourCount = 0; Coord[] NEIGHBOUR = v.Neighbour(); for (int i = 0; i < NEIGHBOUR.Length; i++) { if (!IsCoordValid(NEIGHBOUR[i])) { continue; } int neighbourLayerCount = GetTileLayerCount(NEIGHBOUR[i]); for (int nlayer = 0; nlayer < neighbourLayerCount; nlayer++) { NEIGHBOUR[i].y = nlayer; //Debug.Log(NEIGHBOUR[i].x + "__" + NEIGHBOUR[i].y + "__" + NEIGHBOUR[i].z + "__" ); ushort data = GetHeight(NEIGHBOUR[i]); if ((data & Tile.Walkable) != 0) { int offset = currentHeight - (int)(data & Tile.HeightMask); float f = offset * fYLayerHeight; if (f < 0.5f && f > -0.5f) { neighbourCount++; } } } } if (neighbourCount > 6) { neighbourCount = 6; } neighbourCount = 6 - neighbourCount; current = (ushort)(current | (neighbourCount << 8)); SetHeight(v, current); } } } }