void HeightsGeneration() //CURRENT { int step = 0, dirMain = 5, dirUpto = 1, dirUndo = 3, yCount = hex.GetLength(1) * 2; Hex mainHex = hex[0, 0], underHex, ontoHex; float gpart = 0.3f; while (mainHex != null) { float h = (1 - Mathf.Cos(step / ((float)yCount) * Mathf.PI * 2)) * averageDepth; mainHex.h = h; mainHex.ApplyHeight(); float dh = h; underHex = GetNeighbourCell(mainHex, dirUndo); while (underHex != null) { float delta = maxGap * (gpart + (1 - gpart) * Random.value); if (Random.value < 0.5f) { delta *= -1; } Hex b = GetNeighbourCell(underHex, 1), c = GetNeighbourCell(underHex, 2); float minHeight = dh, maxHeight = dh; if (b != null) { if (b.h > maxHeight) { maxHeight = b.h; } else { if (b.h < minHeight) { minHeight = b.h; } } } if (c != null) { if (c.h > maxHeight) { maxHeight = c.h; } else { if (c.h < minHeight) { minHeight = c.h; } } } underHex.h = dh + delta; if (underHex.h > minHeight + maxGap) { underHex.h = minHeight + maxGap; } else { if (underHex.h < maxHeight - maxGap) { underHex.h = maxHeight - maxGap; } } underHex.ApplyHeight(); //print ("min: "+minHeight.ToString() + ", max: "+ maxHeight.ToString() +", maxGap: " +maxGap.ToString() +", end: "+underHex.h.ToString()); dh = underHex.h; underHex = GetNeighbourCell(underHex, dirUndo); //underHex = null; } // НАД ГЛАВНОЙ ДИАГОНАЛЬЮ : dh = mainHex.h; ontoHex = GetNeighbourCell(mainHex, dirUpto); while (ontoHex != null) { float delta = maxGap * (gpart + (1 - gpart) * Random.value); if (Random.value < 0.5f) { delta *= -1; } Hex b = GetNeighbourCell(ontoHex, 3), c = GetNeighbourCell(ontoHex, 2); float minHeight = dh, maxHeight = dh; if (b != null) { if (b.h > maxHeight) { maxHeight = b.h; } else { if (b.h < minHeight) { minHeight = b.h; } } } if (c != null) { if (c.h > maxHeight) { maxHeight = c.h; } else { if (c.h < minHeight) { minHeight = c.h; } } } ontoHex.h = dh + delta; if (ontoHex.h > minHeight + maxGap) { ontoHex.h = minHeight + maxGap; } else { if (ontoHex.h < maxHeight - maxGap) { ontoHex.h = maxHeight - maxGap; } } //print ("min: "+minHeight.ToString() + ", max: "+ maxHeight.ToString() +", maxGap: " +maxGap.ToString() +", end: "+ontoHex.h.ToString()); ontoHex.ApplyHeight(); dh = ontoHex.h; ontoHex = GetNeighbourCell(ontoHex, dirUpto); //ontoHex = null; } mainHex = GetNeighbourCell(mainHex, dirMain); step++; } }