我正在尝试通过 C# 脚本绘制地形。我希望能够在给定地形上的某些点绘制草,不是在编辑器中,而是在运行时。我唯一需要知道的是:在统一编辑器中用于绘制地形(通常使用画笔工具)的实际函数在哪里?它必须位于脚本中的某个位置,以便我可以调用是吗?我知道还有其他解决方法,但我对这个特别感兴趣。 我感谢任何帮助。
最佳答案
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 组件的预设引用。
关于c# - 哪个函数用于使用 Unity 地形引擎绘制地形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48349866/