Assets/Examples/Scripts/ProceduralWorld.cs
/// <summary>
/// Ensures that a chunk exists at a coordinate. It either moves (from availableChunks) or instantiates a chunk
/// </summary>
/// <param name="chunkCoordinate">The chunk's coordinate</param>
/// <param name="chunk">The chunk at that position</param>
/// <returns>Does a chunk already exist there</returns>
Ensures that a chunk exists at a coordinate. It either moves (from availableChunks) or instantiates a chunk
Ensures that a chunk exists at a coordinate . It either moves ( from availableChunks ) or instantiates a chunk
private bool GetOrCreateChunk(int3 chunkCoordinate, out Chunk chunk)
        {
            if (Chunks.TryGetValue(chunkCoordinate, out Chunk existingChunk))
            {
                chunk = existingChunk;
                return true;
            }
            if (_availableChunks.Count > 0)
            {
                ProceduralChunk proceduralChunk = _availableChunks.Dequeue();
                proceduralChunk.SetCoordinate(chunkCoordinate);
                chunk = proceduralChunk;
                return false;
            }
            chunk = CreateChunk(chunkCoordinate);
            return false;
        }
private bool GetOrCreateChunk ( int3 chunkCoordinate , out Chunk chunk ) { if ( Chunks . TryGetValue ( chunkCoordinate , out Chunk existingChunk ) ) { chunk = existingChunk ; return true ; } if ( _availableChunks . Count > 0 ) { ProceduralChunk proceduralChunk = _availableChunks . Dequeue ( ) ; proceduralChunk . SetCoordinate ( chunkCoordinate ) ; chunk = proceduralChunk ; return false ; } chunk = CreateChunk ( chunkCoordinate ) ; return false ; }
Ensures that a chunk exists at a coordinate.
Ensures that a chunk exists at a coordinate .
Does a chunk already exist there
Does a chunk already exist there
chunkCoordinate
int3
The chunk's coordinate
The chunk ' s coordinate
Chunk
out
chunk
The chunk at that position
The chunk at that position