/// <summary> /// Applied the given visual and collision meshes to the chunk object. /// </summary> /// <param name="chunk">The chunk to refresh.</param> /// <param name="visualMesh">The new visual mesh data.</param> /// <param name="collisionMesh">The new collision mesh data.</param> public void RefreshMeshes(BlockChunk chunk, LayeredProcMesh visualMesh, LayeredProcMesh collisionMesh) { var meshFilter = chunk.GetComponent <MeshFilter>(); var meshCollider = chunk.GetComponent <MeshCollider>(); var meshRenderer = chunk.GetComponent <MeshRenderer>(); UpdateMesh(visualMesh, meshFilter.sharedMesh); UpdateMesh(collisionMesh, meshCollider.sharedMesh); meshRenderer.sharedMaterials = new Material[] { null }; // To trigger a refresh. meshFilter.sharedMesh = meshFilter.sharedMesh; meshCollider.sharedMesh = meshCollider.sharedMesh; }
/// <summary> /// Destroys a chunk game object and attached resources. /// </summary> /// <param name="chunk">The chunk to destroy.</param> public void DestroyChunk(BlockChunk chunk) { Object.DestroyImmediate(chunk.GetComponent <MeshFilter>().sharedMesh); Object.DestroyImmediate(chunk.GetComponent <MeshCollider>().sharedMesh); Object.DestroyImmediate(chunk.gameObject); }