/// <summary> /// Generate chunk from chunk generator /// </summary> private void GenerateChunk() { Vector2 position = ChunkIndex; if (generator != null) { for (int x = 0; x < blocks.GetLength(0); x++) { for (int y = 0; y < blocks.GetLength(1); y++) { blocks[x, y] = generator.GenerateBlock(((position.x * _chunkToWorldSize) + x) * BlockToWorldSize, ((position.y * _chunkToWorldSize) + y) * BlockToWorldSize); // Since Generate directly assigns a block and will not go through SetBlockAtIndex, // Assign the index to the block here if (blocks[x, y] != null) { blocks[x, y].SetIndex(x, y); } } } } IsGenerated = true; }