哪个函数用于使用统一地形引擎绘制地形?

时间:2018-01-19 21:34:20

标签: c# unity3d game-engine paint terrain

我正在尝试通过C#脚本绘制地形。我希望能够在给定地形上的某些点上绘制草,而不是在编辑器中,而是在运行时。我唯一需要知道的是:用于在统一编辑器中绘制地形的实际函数(通常使用画笔工具)在哪里?它必须在脚本中的某个位置才能调用它,不是吗?我知道还有其他的解决方法,但我对这个特别感兴趣。 我感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

Terrain::TerrainData::SetAlphamaps()

该页面上还有一些示例代码:

// Blend the two terrain textures according to the steepness of
// the slope at each point.
function Start () {
    var map: float[,,] = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 2];

    // For each point on the alphamap...
    for (var y = 0; y < t.terrainData.alphamapHeight; y++) {
        for (var x = 0; x < t.terrainData.alphamapWidth; x++) {
            // Get the normalized terrain coordinate that
            // corresponds to the the point.
            var normX = x * 1.0 / (t.terrainData.alphamapWidth - 1);
            var normY = y * 1.0 / (t.terrainData.alphamapHeight - 1);

            // Get the steepness value at the normalized coordinate.
            var angle = t.terrainData.GetSteepness(normX, normY);

            // Steepness is given as an angle, 0..90 degrees. Divide
            // by 90 to get an alpha blending value in the range 0..1.
            var frac = angle / 90.0;
            map[x, y, 0] = frac;
            map[x, y, 1] = 1 - frac;
        }
    }

    t.terrainData.SetAlphamaps(0, 0, map);
}

其中t可能是对示例中未另行声明的Terrain组件的预设引用。