Ejemplo n.º 1
0
    public void CreateChunk(ChunkPos chunkPos)
    {
        WorldPos worldPos = chunkPos.toWorldPos();

        //Instantiate the chunk at its world coordinates
        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(worldPos.x, worldPos.y),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = chunkPos;
        newChunk.world = this;

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(chunkPos, newChunk);

        TriPos startTriPos = chunkPos.toTriPos();

        for (int xi = 0; xi < chunkXSize; xi++)
        {
            for (int yi = 0; yi < chunkYSize; yi++)
            {
                TriPos triPos = new TriPos(startTriPos.x + xi, startTriPos.y + yi);
                SetBlock(triPos, new Block());
            }
        }
    }