/// <summary> /// Calculates data used for placing grass on terrain regardless of /// whether or not this data has already been computed previously. /// Use <c>HasGrassData</c> to check if its already been computed. /// This method calculates grass meshes via a coroutine which calculates a /// mesh and then waits for the next frame before continuing to the next. /// </summary> public static void CalculateGrassMeshes(TerrainTile tile) { GrassTile gt = new GrassTile(tile, TerraSettings.Instance.GrassStepLength); CalculatingTile = true; tile.StartCoroutine(gt.CalculateCells((data) => { List <GameObject> createdGos = new List <GameObject>(data.Count); GameObject parent = SetupGrassParent(tile); foreach (GrassTile.MeshData md in data) { //Apply material to each Mesh if (md.vertices != null) { GameObject grassGO = new GameObject("Grass"); grassGO.transform.parent = parent.transform; createdGos.Add(grassGO); var mf = grassGO.AddComponent <MeshFilter>(); var mr = grassGO.AddComponent <MeshRenderer>(); mr.material = Material; Mesh m = new Mesh(); m.SetVertices(md.vertices); m.SetNormals(md.normals); m.SetIndices(md.indicies.ToArray(), MeshTopology.Points, 0); mf.mesh = m; } } CachedMeshData.Add(tile, createdGos); CalculatingTile = false; })); }