/// <summary> /// Checks if chunk building jobs are ready /// </summary> private IEnumerator ChunkLoading() { var wait = new WaitForSecondsRealtime(1f / buildChecksPerSecond); while (true) { yield return(wait); if (chunkBuildingJobs.Count > 0) { for (int i = 0; i < maxChunksToBuildAtOnce; i++) { if (chunkBuildingJobs.Peek().IsCompleted) { chunkBuildingJobs.Dequeue().Complete(); Chunk tc = terrainChunks.Dequeue(); tc.gameObject.SetActive(true); tc.CreateBiomeTexture(); tc.Animation(); tc.ApplyMesh(); LoadedChunks++; yield return(null); if (chunkBuildingJobs.Count == 0) { break; } // TODO: check if player is close // ChunkLoading(); } else { break; } } } while (meshBakingJobs.Count > 0) { if (meshBakingJobs.Peek().IsCompleted) { meshBakingJobs.Dequeue().Complete(); Chunk chunk = terrainCollisionMeshes.Dequeue(); chunk.BlockMeshCollider.sharedMesh = chunk.BlockMeshFilter.mesh; } } TimeToBuild?.Invoke(); } }
/// <summary> /// Checks if chunk building jobs are ready /// </summary> private void ChunkLoading() { if (pendingJobs.Count > 0) { for (int i = 0; i < maxChunksToBuildAtOnce; i++) { if (pendingJobs.Peek().IsCompleted) { pendingJobs.Dequeue().Complete(); Chunk tc = terrainChunks.Dequeue(); tc.gameObject.SetActive(true); tc.CreateBiomeTexture(); tc.Animation(); tc.ApplyMesh(); LoadedChunks++; if (pendingJobs.Count == 0) { break; } // TODO: check if player is close // ChunkLoading(); } else { break; } } } while (meshBakingJobs.Count > 0) { if (meshBakingJobs.Peek().IsCompleted) { meshBakingJobs.Dequeue().Complete(); Chunk chunk = terrainCollisionMeshes.Dequeue(); chunk.BlockMeshCollider.sharedMesh = chunk.BlockMeshFilter.mesh; } } TimeToBuild.Invoke(); }