Exemplo n.º 1
0
 void UpdateVoxelChunks(VoxelData data)
 {
     //Loop trough the x y and z coordinates
     //Loop trough the x y and z coordinates
     for (int cz = 0; cz < chunksAxisX; cz++)
     {
         for (int cy = 0; cy < chunksAxisY; cy++)
         {
             for (int cx = 0; cx < chunksAxisZ; cx++)
             {
                 if (data.EmptyChunk(chunkSize, new Vector3(cx, cy, cz)))
                 {
                     chunks[cx, cy, cz].SetActive(false);
                 }
                 else
                 {
                     chunks[cx, cy, cz].SetActive(true);
                     chunks[cx, cy, cz].GetComponent <ChunkRender>().UpdateChunkMesh(data, new Vector3(cx, cy, cz), chunkSize, blockScale);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    //This function generates the vertices and triangles based on the given data
    void GenerateVoxelChunks(VoxelData data)
    {
        for (int x = 0; x < chunks.GetLength(0); x++)
        {
            for (int y = 0; y < chunks.GetLength(1); y++)
            {
                for (int z = 0; z < chunks.GetLength(2); z++)
                {
                    Destroy(chunks[x, y, z]);
                }
            }
        }
        chunks = new GameObject[chunksAxisX, chunksAxisY, chunksAxisZ];

        //Loop trough the x y and z coordinates
        for (int z = 0; z < chunksAxisZ; z++)
        {
            for (int y = 0; y < chunksAxisY; y++)
            {
                for (int x = 0; x < chunksAxisX; x++)
                {
                    tempChunk = Instantiate(chunkPrefab);
                    if (data.EmptyChunk(chunkSize, new Vector3(x, y, z)))
                    {
                        tempChunk.SetActive(false);
                    }
                    else
                    {
                        tempChunk.GetComponent <ChunkRender>().UpdateChunkMesh(data, new Vector3(x, y, z), chunkSize, blockScale);
                    }
                    tempChunk.transform.parent = transform;
                    chunks[x, y, z]            = tempChunk;
                }
            }
        }
    }