public IEnumerator GenerationCoroutine() { vertices.Clear(); triangles.Clear(); submeshes = new List <int> [materials.Count()]; triangleIndex = 0; int rows = chunk.size; int columns = chunk.size; for (int z = 0, i = 0; z < rows; z++) { for (int x = 0; x < columns; x++) { CellStack stack = chunk.GetCellStackFromChunkOffset(new Vector2(x, z)); if (stack != null) { yield return(Ninja.JumpToUnity); GenerateStackMesh(x, z, stack); yield return(Ninja.JumpBack); } } } yield return(Ninja.JumpToUnity); terrainRenderMesh.Clear(); terrainRenderMesh.vertices = vertices.ToArray(); terrainRenderMesh.triangles = triangles.ToArray(); //Create a submesh for each material terrainRenderMesh.subMeshCount = submeshes.Count(); //Set material for each submesh meshRenderer.materials = materials; for (int i = 0; i < submeshes.Count(); i++) { if (submeshes[i] != null) { terrainRenderMesh.SetTriangles(submeshes[i], i); } } terrainRenderMesh.RecalculateNormals(); terrainRenderMesh.RecalculateBounds(); yield return(Ninja.JumpBack); }
public IEnumerator GenerationCoroutine() { vertices.Clear(); triangles.Clear(); int rows = chunk.size; int columns = chunk.size; for (int z = 0, i = 0; z < rows; z++) { for (int x = 0; x < columns; x++) { CellStack stack = chunk.GetCellStackFromChunkOffset(new Vector2(x, z)); if (stack != null) { yield return(Ninja.JumpToUnity); GenerateStackMesh(x, z, stack); yield return(Ninja.JumpBack); } } } yield return(Ninja.JumpToUnity); terrainMesh.Clear(); terrainMesh.vertices = vertices.ToArray(); terrainMesh.triangles = triangles.ToArray(); terrainMesh.RecalculateNormals(); terrainMesh.RecalculateBounds(); meshCollider.sharedMesh = terrainMesh; yield return(Ninja.JumpBack); //navMeshSurface.BuildNavMesh(); }