Beispiel #1
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(x, y, z),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

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

        newChunkObject.layer = LayerMask.NameToLayer("Blocks");
        newChunk.pos         = worldPos;
        newChunk.world       = this;

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

        var terrainGen = new TerrainGenerator();

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        Serialization.LoadChunk(newChunk);
    }
    // threaded task. Don't use Unity API here
    protected override void ThreadFunction()
    {
        Chunk current;

        for (int i = 0; i < queue.Count; i++)
        {
            current          = queue[i].Chunk;
            current.worldPos = queue[i].WorldPosition;
            current.world    = queue[i].World;

            current = tGenerator.ChunkGen(current);
            current.SetBlocksUnmodified();

            // store a copy to return
            finishedChunks.Add(current);

            //Serialization.Load(current);
        }

        queue.Clear();
    }