Returns the MapChunk at the given Block coordinates.
Useful in niche cases.
I'll provide the one nice instance that I have used in the example below.
It is also useful to be able to fetch the MapChunk at 0,0,0 in order to orient maps to your camera nicely. I'll leave the logic there to you, the mathematics are much too long for this little grey example box. To provide you with an understanding of how this works:
If you have a chunkWidth and chunkHeight of 5 and 5 respectively, then queries to GetChunkAtCoordinates() with arguments between 0...4 will return the same MapChunk (as this is the MapChunk hosting the Block coordinates provided).
Definition:
MapChunk GetChunkAtCoordinates(BlockMap map, int x, int y, int depth)
Example: This is an exceptionally handy little sample - this will retrieve a chunk from the given Block coordinate, check if it is empty, and if so - remove it from the map. Use this judiciously (i.e only if you are 100% confident that this is what you want). The use-case I have in mind is for an 'infinite runner' style of map generation - where we will be quickly moving through many chunks and don't wish to leave a billion empty chunks in our wake. This function is not integrated internally into the toolkit, as it is very use-case specific. MapChunk chunk = map.GetChunkForBlockCoordinate(x,y,z); if(chunk != null){ if(chunk.chunkPieces != null){ for(int i = 0; i < chunk.chunkPieces.Length; i++){ if(chunk.chunkPieces[i] != null){ return; } } } map.RemoveChunkAt(chunk.x,chunk.y,chunk.depth); GameObject.Destroy(chunk.gameObject); } |