x | 要读取的 x 偏移。 |
y | 要读取的 y 偏移。 |
width | 要读取的 Alpha 贴图区域的宽度。 |
height | 要读取的 Alpha 贴图区域的高度。 |
float[,,] 一个三维的浮点值数组,其中第三个维度表示每个 (x,y) 坐标处的每个泼溅贴图的混合权重。
返回位置 x、y 处给定宽度和高度的 Alpha 贴图。
返回的数组是三维的 - 前两个维度表示贴图上的 x 和 y 坐标, 第三个维度表示应用该 Alpha 贴图的泼溅纹理。
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
// Add some random "noise" to the alphamaps.
void AddAlphaNoise(Terrain t, float noiseScale)
{
float[,,] maps = t.terrainData.GetAlphamaps(0, 0, t.terrainData.alphamapWidth, t.terrainData.alphamapHeight);
for (int y = 0; y < t.terrainData.alphamapHeight; y++)
{
for (int x = 0; x < t.terrainData.alphamapWidth; x++)
{
float a0 = maps[x, y, 0];
float a1 = maps[x, y, 1];
a0 += Random.value * noiseScale;
a1 += Random.value * noiseScale;
float total = a0 + a1;
maps[x, y, 0] = a0 / total;
maps[x, y, 1] = a1 / total;
}
}
t.terrainData.SetAlphamaps(0, 0, maps);
}
}