void UpdateVisibleChunks() { var alreadyUpdatedChunkCoords = new List <Vector2>(); for (var i = visibleWorldChunks.Count - 1; i >= 0; i--) { visibleWorldChunks[i].UpdateWorldChunk(); alreadyUpdatedChunkCoords.Add(visibleWorldChunks[i].coord); } var currentChunkCoordX = Mathf.RoundToInt(viewerPosition.x / meshWorldSize); var currentChunkCoordY = Mathf.RoundToInt(viewerPosition.y / meshWorldSize); for (var yOffset = -chunksVisibleInViewDst; yOffset <= chunksVisibleInViewDst; yOffset++) { for (var xOffset = -chunksVisibleInViewDst; xOffset <= chunksVisibleInViewDst; xOffset++) { var viewedChunkCoord = new Vector2(currentChunkCoordX + xOffset, currentChunkCoordY + yOffset); if (!alreadyUpdatedChunkCoords.Contains(viewedChunkCoord)) { alreadyUpdatedChunkCoords.Add(viewedChunkCoord); if (worldChunkDict.TryGetValue(viewedChunkCoord, out var worldChunk)) { worldChunk.UpdateWorldChunk(); } else { var newChunk = new WorldChunk(viewedChunkCoord, heightMapSettings, meshSettings, detailLevels, colliderLODIndex, transform, viewer, mapMaterial, worldSettings); worldChunkDict.Add(viewedChunkCoord, newChunk); newChunk.onVisibilityChanged += OnWorldChunkVisibilityChanged; newChunk.Load(erosion, worldSettings); } } } } }