예제 #1
0
 private void OnTerrainChunkVisibilityChanged(TerrainChunk chunk, bool isVisible)
 {
     if (isVisible)
     {
         visibleTerrainChunks.Add(chunk);
     }
     else
     {
         visibleTerrainChunks.Remove(chunk);
     }
 }
예제 #2
0
        void UpdateVisibleChunks()
        {
            chunkVisibilityEvaluationPosition2d = currentPosition2d;

            var alreadyUpdatedChunkCoords = new HashSet <Vector2>();

            for (var i = visibleTerrainChunks.Count - 1; i >= 0; i--)
            {
                alreadyUpdatedChunkCoords.Add(visibleTerrainChunks[i].coord);
                visibleTerrainChunks[i].UpdateTerrainChunk();
            }

            var currentChunkCoordX = Mathf.RoundToInt(currentPosition2d.x / meshSettings.meshWorldSize);
            var currentChunkCoordY = Mathf.RoundToInt(currentPosition2d.y / meshSettings.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))
                    {
                        if (terrainChunkDictionary.ContainsKey(viewedChunkCoord))
                        {
                            terrainChunkDictionary[viewedChunkCoord].UpdateTerrainChunk();
                        }
                        else
                        {
                            var newChunk = new TerrainChunk(this, viewedChunkCoord, globalSettings, heightMapSettings, meshSettings, detailLevels, colliderLodIndex, mapMaterial);
                            terrainChunkDictionary.Add(viewedChunkCoord, newChunk);
                            newChunk.onVisibilityChanged += OnTerrainChunkVisibilityChanged;
                            newChunk.Load();
                        }
                    }
                }
            }
        }