Example #1
0
    void GenerateGroundTexture()
    {
        groundHeightMapPreview            = new Texture2D(300, 300);
        groundHeightMapPreview.filterMode = FilterMode.Point;
        groundHeightMapPreview.wrapMode   = TextureWrapMode.Clamp;

        GroundMap groundMap = Utility.GetTargetObjectOfProperty(groundMapProperty) as GroundMap;

        var nbXPixel = groundHeightMapPreview.width / (Chunk.ChunkSize * 5);
        var nbYPixel = groundHeightMapPreview.height / (Chunk.ChunkSize * 5);

        for (int j = 0; j < Chunk.ChunkSize * 5; j++)
        {
            for (int i = 0; i < Chunk.ChunkSize * 5; i++)
            {
                var height = groundMap.GetHeightUnscale(i - Chunk.ChunkRadius, j - Chunk.ChunkRadius);
                var color  = Color.Lerp(Color.black, Color.white, height);

                var colors = Enumerable.Repeat <Color>(color, nbXPixel * nbYPixel).ToArray();
                groundHeightMapPreview.SetPixels(i * nbXPixel, j * nbYPixel, nbXPixel, nbYPixel, colors);
            }
        }

        groundHeightMapPreview.Apply();
    }