/// <summary> /// Looks for chunk map at given world position. /// </summary> /// <param name="worldPosition">The world position.</param> /// <returns>The chunk map (can be null when doesn't exist).</returns> public ChunkMap FindChunkMap(Vector3Int worldPosition) { // Convert worldPosition to chunk map offset var offset = ChunkMap.WorldToMapOffset(worldPosition); return(_chunkMaps.TryGetValue(offset, out var map) ? map : null); }
/// <summary> /// Looks for chunk map at given world position, /// when chunk map is not found, this function creates one. /// </summary> /// <param name="worldPosition">The world position.</param> /// <returns>The chunk map.</returns> public ChunkMap FindOrAddChunkMap(Vector3Int worldPosition) { // Convert worldPosition to chunk map offset var offset = ChunkMap.WorldToMapOffset(worldPosition); // Try to find the chunk map with the same calculated map offset if (!_chunkMaps.TryGetValue(offset, out var map)) { // Not found, create and add map = new ChunkMap(offset); // Add chunk map _chunkMaps.Add(offset, map); } return(map); }