c# - 哪个函数用于使用 Unity 地形引擎绘制地形?

标签 c# unity-game-engine game-engine paint terrain

我正在尝试通过 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/

相关文章:

C# 与 C DLL 互操作,如何编码从函数返回长度的 char 数组?

c# - C# asp.net Core 中的 Image 类型等效于什么?

c# - OpenXmlPowerTools DocumentBuilder 在单独的页面上合并文档

c# - 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据?

unity-game-engine - 网格碰撞器在应该有孔的地方有墙壁并且变形了

c# - 使变量成为必需的 - 以逃避 NullReferenceException?

android - iOS + Android 2D 游戏引擎

c# - 如何在实例化相机上应用渲染纹理(作为目标纹理)?

c# - 用于计算着色器步幅的自定义结构体的 sizeof

architecture - 游戏状态如何与基于组件的实体交互?