Version: 2020.2
public float[,,] GetAlphamaps (int x, int y, int width, int height);

参数

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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961