protected override void OnProcessChunk(Chunk chunk) { Profiler.BeginSample("ProcessChunk"); int xd = (viewerPos.x - chunk.Pos.x) / Env.CHUNK_SIZE; int yd = (viewerPos.y - chunk.Pos.y) / Env.CHUNK_SIZE; int zd = (viewerPos.z - chunk.Pos.z) / Env.CHUNK_SIZE; // Remove the chunk if it is too far away if ( !ChunkLoadOrder.CheckXZ(xd, zd, horizontalChunkLoadRadius) || !ChunkLoadOrder.CheckY(yd, verticalChunkLoadRadius) ) { chunk.RequestRemoval(); } else { // Dummy collider example - create a collider for chunks directly surrounding the viewer chunk.NeedsColliderGeometry = Helpers.Abs(xd) <= 1 && Helpers.Abs(zd) <= 1; if (!useFrustumCulling) { // Update visibility information chunk.NeedsRenderGeometry = true; chunk.PossiblyVisible = true; } } Profiler.EndSample(); }
public bool CheckInsideWorld(Vector3Int pos) { int offsetX = (Bounds.maxX + Bounds.minX) >> 1; int offsetZ = (Bounds.maxZ + Bounds.minZ) >> 1; int xx = (pos.x - offsetX) / Env.CHUNK_SIZE; int zz = (pos.z - offsetZ) / Env.CHUNK_SIZE; int yy = pos.y / Env.CHUNK_SIZE; int horizontalRadius = (Bounds.maxX - Bounds.minX) / (2 * Env.CHUNK_SIZE); return(ChunkLoadOrder.CheckXZ(xx, zz, horizontalRadius) && yy >= (Bounds.minY / Env.CHUNK_SIZE) && yy <= (Bounds.maxY / Env.CHUNK_SIZE)); }
private void OnDrawGizmosSelected() { if (!enabled) { return; } float size = Env.CHUNK_SIZE * Env.BLOCK_SIZE; float halfSize = size * 0.5f; float smallSize = size * 0.25f; if (world != null && (diag_DrawWorldBounds || diag_DrawLoadRange)) { foreach (Chunk chunk in updateRequests) { if (diag_DrawWorldBounds) { // Make central chunks more apparent by using yellow color bool isCentral = chunk.Pos.x == viewerPos.x || chunk.Pos.y == viewerPos.y || chunk.Pos.z == viewerPos.z; Gizmos.color = isCentral ? Color.yellow : Color.blue; Vector3 chunkCenter = new Vector3( chunk.Pos.x + (Env.CHUNK_SIZE >> 1), chunk.Pos.y + (Env.CHUNK_SIZE >> 1), chunk.Pos.z + (Env.CHUNK_SIZE >> 1) ); Vector3 chunkSize = new Vector3(Env.CHUNK_SIZE, Env.CHUNK_SIZE, Env.CHUNK_SIZE); Gizmos.DrawWireCube(chunkCenter, chunkSize); } if (diag_DrawLoadRange) { int xd = (viewerPos.x - chunk.Pos.x) / Env.CHUNK_SIZE; int zd = (viewerPos.z - chunk.Pos.z) / Env.CHUNK_SIZE; if (ChunkLoadOrder.CheckXZ(xd, zd, horizontalChunkLoadRadius)) { Gizmos.color = Color.green; Gizmos.DrawWireCube( new Vector3(chunk.Pos.x + halfSize, 0, chunk.Pos.z + halfSize), new Vector3(size - 1f, 0, size - 1f) ); } else { Gizmos.color = Color.red; Gizmos.DrawWireCube( new Vector3(chunk.Pos.x + halfSize, 0, chunk.Pos.z + halfSize), new Vector3(size - 1f, 0, size - 1f) ); } // Show generated chunks if (chunk.IsStateCompleted(ChunkState.Generate)) { Gizmos.color = Color.magenta; Gizmos.DrawWireCube( new Vector3(chunk.Pos.x + halfSize, 0, chunk.Pos.z + halfSize), new Vector3(smallSize - 0.05f, 0, smallSize - 0.05f) ); } } } } }