微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C#-如何在代码中更改地形纹理

我想通过代码更改地形纹理的偏移量(2).
我已经添加了道路图像作为地形上的纹理.
我已经在网上找到相关的代码,但是在这种情况下我无法弄清楚渲染器的作用.

我不只是代码,我只是想知道为了通过代码更改纹理而应该采取的第一步. (基本设置).
并且请提及渲染器的角色.

enter image description here

解决方法:

在Unity Terrains中,纹理由SplatPrototype类处理. See documentation

A Splat prototype is just a texture that is used by the TerrainData.

因此,如果要更改地形的纹理,则必须创建一个新的SplatPrototype并将其设置为TerrainData的splatPrototype变量.

您可以在此处设置您选择的Metallic,normalMap,平滑度,纹理,tileSize和tileOffset的值.

您可以使用以下方法

private void SetTerrainSplatMap(Terrain terrain, Texture2D[] textures)
{
    var terrainData = terrain.terrainData;

    // The Splat map (Textures)
    SplatPrototype[] splatPrototype = new SplatPrototype[terrainData.splatPrototypes.Length];
    for (int i = 0; i < terrainData.splatPrototypes.Length; i++)
    {
        splatPrototype[i] = new SplatPrototype();
        splatPrototype[i].texture = textures[i];    //Sets the texture
        splatPrototype[i].tileSize = new Vector2(terrainData.splatPrototypes[i].tileSize.x, terrainData.splatPrototypes[i].tileSize.y);    //Sets the size of the texture
        splatPrototype[i].tileOffset = new Vector2(terrainData.splatPrototypes[i].tileOffset.x, terrainData.splatPrototypes[i].tileOffset.y);    //Sets the size of the texture
    }
    terrainData.splatPrototypes = splatPrototype;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐