/// <summary> /// Instantiates a chunk at a coordinate /// </summary> /// <param name="chunkCoordinate">The chunk's coordinate</param> /// <returns>The created chunk</returns> private ProceduralChunk CreateChunk(int3 chunkCoordinate) { ProceduralChunk chunk = Instantiate(ChunkPrefab, (chunkCoordinate * ChunkSize).ToVectorInt(), Quaternion.identity).GetComponent <ProceduralChunk>(); chunk.World = this; chunk.Initialize(ChunkSize, Isolevel, chunkCoordinate); return(chunk); }
/// <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> 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); }