1..............
Texture2D newTexture;
Color[] sourceColors;
int sourceWidth;
int sourceHeight;
Color[] newColors;
int newWidth;
public void SplitImg(Texture2D t2d)
{
// 读取源Texture
sourceColors = t2d.GetPixels();
sourceWidth = t2d.width;
sourceHeight = t2d.height;
// 创建新Texture的颜色数组
newColors = new Color[sourceColors.Length];
// 复制源Texture的一半到新Texture
newWidth = sourceWidth / 2;
for (int y = 0; y < sourceHeight; y++)
{
for (int x = 0; x < newWidth; x++)
{
int sourceIndex = y * sourceWidth + x;
int newIndex = y * newWidth + x;
newColors[newIndex] = sourceColors[sourceIndex];
}
}
// 创建新Texture
newTexture = new Texture2D(newWidth, sourceHeight);
newTexture.SetPixels(newColors);
newTexture.Apply();
}
2................
Texture2D newTexture;
void Start
{
newTexture = new Texture2D(615, 615);
}
public void SplitImg(Texture2D t2d)
{
newColors = t2d.GetPixels(0, 0, 615, 615);
//将数据设置到新纹理中
newTexture.SetPixels(newColors);
//应用修改
newTexture.Apply();
}