コード例 #1
0
    private void GenerateVisualizedHeight(bool firstRun)
    {
        /*
         * int bandFactor = Mathf.FloorToInt(_terrain.width / FrequencyBands.Length);
         * int currentVertex = 0;
         * for (int y = 0; y < _terrain.height; y++)
         * {
         *  for (int i = 0; i < _terrain.width; i++)
         *  {
         *      _terrain.SetVertexHeight(currentVertex, Random.Range(0f, 30f));
         *      currentVertex++;
         *      //_heights[i, y] = FrequencyBands[Mathf.FloorToInt(i / bandFactor)].smoothedFrequency;
         *  }
         * }
         */
        Chunk baseChunk  = _terrain.chunks[0];
        int   startIndex = firstRun ? 0 : 3;

        for (int u = 0; u < 3; u++)
        {
            _terrain.ReplaceChunk(_terrain.chunks[u], _terrain.chunks[u + 6]);
        }

        int bandFactor = Mathf.FloorToInt(_terrain.width / FrequencyBands.Length);

        Debug.Log(FrequencyBands[0].frequency);
        for (int c = startIndex; c < _terrain.chunks.Length; c++)
        {
            Chunk chunk = _terrain.chunks[c];
            for (int y = 0; y < baseChunk.height; y++)
            {
                for (int x = 0; x < baseChunk.width; x++)
                {
                    Vector2Int vertex = chunk.MapToChunkBounds(x, y);
                    Vector3    vert   = _terrain.Vertices[_terrain.ToSingleIndex(vertex.x, vertex.y)];
                    vert.y = Mathf.PerlinNoise(x * perlinNoiseZoom.x, y * perlinNoiseZoom.y) * heightScalar;
                    _terrain.Vertices[_terrain.ToSingleIndex(vertex.x, vertex.y)] = vert;
                }
            }
        }
        _terrain.ApplyVertexChanges();
    }