你没有索引到
Color
正确排列。用你正在使用的索引,
y+x
,则在纹理的最低行上不断检查相同的值,而不会超过某个点。
Texture2D tex = mapImage.mainTexture as Texture2D;
int w = tex.width;
int h = tex.height;
Vector4[,] vals = new Vector4[w, h];
Color[] cols = tex.GetPixels();
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int index = y * w + x;
vals[x, y] = cols[index];
}
}
关于
GetPixels
:
返回的数组是一个扁平的2D数组,像素从左到右、从下到上(即一行接一行)。
数组大小是所使用的mip级别的宽度和高度。默认mip level为零(基本纹理),在这种情况下,大小只是纹理的大小。一般情况下,mip级别大小为
mipWidth=max(1,width>>miplevel)
身高也一样。