public List <IslandObject> GenerateIslands(List <int> islands, int level) { List <IslandObject> ret = new List <IslandObject>(); foreach (int isle in islands) { IslandObject tmp = GenerateIsland(isle, level); if (tmp != null) { ret.Add(tmp); } } return(ret); }
public void GenerateObjects(TerrainObject objectInfo) { cleanUpObjects(); int width = heightMap.GetLength(0); int height = heightMap.GetLength(1); NoiseParameters noiseParameters = objectInfo.noise; float[,] noiseMap = Noise.GenerateNoiseMap(width, height, Random.Range(0, int.MaxValue), noiseParameters.noiseScale, noiseParameters.octaves, noiseParameters.persistance, noiseParameters.lacunarity, Vector2.zero); float startHeight = heightCurve.Evaluate(objectInfo.startHeight) * heightMultiplier; float endHeight = heightCurve.Evaluate(objectInfo.endHeight) * heightMultiplier; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { float y = heightCurve.Evaluate(heightMap[i, j]) * heightMultiplier; if (y >= startHeight && y <= endHeight && noiseMap[i, j] > objectInfo.noiseThreshold) { Vector3 pos = new Vector3((width - 1) / -2f + i, y, (height - 1) / 2f - j) * uniformScale; pos += new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) * 0.2f; pos += transform.position; IslandObject obj = Instantiate(objectInfo.prefab, pos, Quaternion.identity); obj.transform.SetParent(objectContainer, true); obj.Generate(); // Align the rotation of the object to the normal of the terrain at that point if (objectInfo.alignToNormal) { Ray ray = new Ray(pos + Vector3.up * 10, Vector3.down); RaycastHit hitInfo; bool hit = mesh.meshCollider.Raycast(ray, out hitInfo, Mathf.Infinity); if (hit) { obj.transform.up = hitInfo.normal; } } } } } }