Example #1
0
    void Start()
    {
        moistureNoiseGen.Seed = (elevationNoiseGen.Seed = Random.Range(0, int.MaxValue)) + 1;

        BlockLength  = prefabForestGrassBlock.GetComponent <Renderer>().bounds.extents.x * 2;
        BlockLength += blockSeparation;

        for (int row = 0; row < loadChunkDistance; ++row)
        {
            var rowChunks = new List <Chunk>();
            for (int col = 0; col < loadChunkDistance; ++col)
            {
                var chunk = new GameObject().AddComponent <Chunk>();

                var chunkOffset = new Vector2(
                    chunk.ZOffset   = chunk.Row = row
                    , chunk.XOffset = chunk.Col = col);
                chunk.BiomeType     = GetChunkType(
                    elevationNoiseGen.GetValue(chunkOffset[0], 0.1, chunkOffset[1])
                    , moistureNoiseGen.GetValue(chunkOffset[0], 0.1, chunkOffset[1]));
                //chunk.type = (Chunk.EType)System.Math.Round(
                //    (elevationNoiseGen.GetValue(col, 0.1, row) / 2 + 0.5) * ((int)Chunk.EType.count - 1));

                chunk.Length             = chunkSize;
                chunk.transform.position = new Vector3(
                    col * chunkSize * BlockLength
                    , 0
                    , row * chunkSize * BlockLength);
                chunk.name = string.Format("Chunk[{0}][{1}]", row, col);

                rowChunks.Add(chunk.Generate());
                encounteredChunks.Add(chunkOffset);
            }
            chunks.Add(rowChunks);
        }
        ChunkEventSignals.DoChunkUpdated();
    }