TerrainData.SetAlphamaps
Declaration
public void SetAlphamaps(int x, int y, float[,,] map);Описание
Назначить все значения splat в заданной области карты.
Массив, предоставленный этой функции, определяет ширину и высоту части, которая будет заменена. Третье измерение массива соответствует количеству текстур splatmap. Обратите внимание, что порядок массива [y,x,i].
using UnityEngine;
public class Example : MonoBehaviour { public Terrain t; // Blend the two terrain textures according to the steepness of // the slope at each point. void Start() { float[,,] map = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 2];
// For each point on the alphamap... for (int y = 0; y < t.terrainData.alphamapHeight; y++) { for (int x = 0; x < t.terrainData.alphamapWidth; x++) { // Get the normalized terrain coordinate that // corresponds to the point. float normX = x * 1.0f / (t.terrainData.alphamapWidth - 1); float normY = y * 1.0f / (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;
// Note the y and x are not in the traditional order. map[y, x, 0] = (float)frac; map[y, x, 1] = (float)(1 - frac); } } t.terrainData.SetAlphamaps(0, 0, map); } }