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;
// 創(chuàng)建新Texture的顏色數(shù)組
newColors = new Color[sourceColors.Length];
// 復(fù)制源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];
}
}
// 創(chuàng)建新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);
//將數(shù)據(jù)設(shè)置到新紋理中
newTexture.SetPixels(newColors);
//應(yīng)用修改
newTexture.Apply();
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。