格式
typescript
Texture2D.SetPixels(x, y, blockWidth, blockHeight, colors, mipLevel)所属类: Texture2D
描述
设置纹理上特定区域的像素颜色。
它可以用于设置纹理中特定区域的颜色信息,使您能够在运行时更新纹理的像素数据。
参数
| 参数名 | 类型 | 描述 |
|---|---|---|
| x | number | x轴坐标 |
| y | number | y轴坐标 |
| blockWidth | number | 待设置区域的宽度 |
| blockHeight | number | 待设置区域的高度 |
| colors | Color[] | 待设置到区域的颜色数组。 |
| mipLevel | number | mip贴图级别 |
返回值
| 类型 | 描述 |
|---|---|
void |
代码示例
typescript
let tex = Resources.Load<Texture2D>(Texture2D, "texture2dID");
if (tex == null) {
throw new Exception("failed to load texture2d: " + "texture2dID");
}
let len = tex.width * tex.height;
let color_arr: Color[] = new Array(len);
for (let i = 0; i < color_arr.length; i++) {
color_arr[i] = Color.green;
}
tex.SetPixels(0, 0, tex.width, tex.height, color_arr, 0);