Unity 瓦片地圖

http://code-phi.com/infinite-terrain-generation-in-unity-3d/

private void ApplyTextures(TerrainData terrainData)

{

    var flatSplat = new SplatPrototype();

    var steepSplat = new SplatPrototype();

 

    flatSplat.texture = Settings.FlatTexture;

    steepSplat.texture = Settings.SteepTexture;

 

    terrainData.splatPrototypes = new SplatPrototype[]

    {

        flatSplat,

        steepSplat

    };

 

    terrainData.RefreshPrototypes();

 

    var splatMap = new float[terrainData.alphamapResolution, terrainData.alphamapResolution, 2];

 

    for (var zRes = 0; zRes < terrainData.alphamapHeight; zRes++)

    {

        for (var xRes = 0; xRes < terrainData.alphamapWidth; xRes++)

        {

            var normalizedX = (float)xRes / (terrainData.alphamapWidth - 1);

            var normalizedZ = (float)zRes / (terrainData.alphamapHeight - 1);

 

            var steepness = terrainData.GetSteepness(normalizedX, normalizedZ);

            var steepnessNormalized = Mathf.Clamp(steepness / 1.5f, 0, 1f);

 

            splatMap[zRes, xRes, 0] = 1f - steepnessNormalized;

            splatMap[zRes, xRes, 1] = steepnessNormalized;

        }

    }

 

    terrainData.SetAlphamaps(0, 0, splatMap);

}

贴图设置

                Texture2D tileTexture = new Texture2D(256, 256, TextureFormat.RGB24, false);
                tileTexture.LoadImage(File.ReadAllBytes(path));
                tileTexture.wrapMode = TextureWrapMode.Clamp;

取消mipmap

你可能感兴趣的:(Unity3D)