Exemplo n.º 1
0
    TerrainChunkObject LoadChunk(ChunkPos cp, bool instant)
    {
        if (chunks.ContainsKey(cp))
        {
            return(chunks[cp]);
        }

        TerrainChunk chunk = TerrainChunkGenerator.request(cp, instant);

        if (chunk == null)
        {
            return(null);
        }

        int                xPos        = cp.x;
        int                zPos        = cp.z;
        GameObject         chunkGO     = Instantiate(terrainChunkPrefab, new Vector3(xPos, 0, zPos), Quaternion.identity);
        TerrainChunkObject chunkObject = chunkGO.GetComponent <TerrainChunkObject>();

        chunkObject.transform.parent = transform;
        chunkObject.name             = "Chunk:" + cp;

        chunkObject.BuildMesh(chunk);

        WaterChunk wat = chunkObject.transform.GetComponentInChildren <WaterChunk>();

        wat.SetLocs(chunk.blocks, chunkObject.Chunk);

        wat.BuildMesh();

        chunks.Add(cp, chunkObject);

        return(chunkObject);
    }
Exemplo n.º 2
0
    private void BuildChunk(int4 chunkPos, int3[] blocks)
    {
        if (chunks.ContainsKey(chunkPos))
        {
            return;
        }
        Chunk chunk;

        if (pooledChunks.Count > 0)
        {
            chunk = pooledChunks[0];
            chunk.gameObject.SetActive(true);
            pooledChunks.RemoveAt(0);
            chunk.transform.position = new Vector3(chunkPos.x * Chunk.Width, chunkPos.y * Chunk.Height, chunkPos.z * Chunk.Width);
        }
        else
        {
            GameObject chunkGO = Instantiate(GameAssets.i.pfChunk.gameObject, new Vector3(chunkPos.x * Chunk.Width, chunkPos.y * Chunk.Height, chunkPos.z * Chunk.Width), Quaternion.identity);
            chunk = chunkGO.GetComponent <Chunk>();
        }

        GenerateTrees(chunkPos, ref blocks);
        chunk.blocks = blocks;

        WaterChunk wat = chunk.transform.GetComponentInChildren <WaterChunk>();

        wat.SetLocs(chunk.blocks);
        wat.BuildMesh();

        chunk.BuildMesh();
        chunks.Add(chunkPos, chunk);
    }
Exemplo n.º 3
0
    void BuildChunk(int xPos, int zPos)
    {
        TerrainChunk chunk;

        if (pooledChunks.Count > 0)//look in the poo first
        {
            chunk = pooledChunks[0];
            chunk.gameObject.SetActive(true);
            pooledChunks.RemoveAt(0);
            chunk.transform.position = new Vector3(xPos, 0, zPos);
        }
        else
        {
            GameObject chunkGO = Instantiate(terrainChunk, new Vector3(xPos, 0, zPos), Quaternion.identity);
            chunk = chunkGO.GetComponent <TerrainChunk>();
        }


        for (int x = 0; x < TerrainChunk.chunkWidth + 2; x++)
        {
            for (int z = 0; z < TerrainChunk.chunkWidth + 2; z++)
            {
                for (int y = 0; y < TerrainChunk.chunkHeight; y++)
                {
                    //if(Mathf.PerlinNoise((xPos + x-1) * .1f, (zPos + z-1) * .1f) * 10 + y < TerrainChunk.chunkHeight * .5f)
                    chunk.blocks[x, y, z] = GetBlockType(xPos + x - 1, y, zPos + z - 1);
                }
            }
        }


        GenerateTrees(chunk.blocks, xPos, zPos);

        chunk.BuildMesh();


        WaterChunk wat = chunk.transform.GetComponentInChildren <WaterChunk>();

        wat.SetLocs(chunk.blocks);
        wat.BuildMesh();



        chunks.Add(new ChunkPos(xPos, zPos), chunk);
    }