Unity CombineTexture

public Texture2D CombineTexture(Texture2D background, Texture2D top)
{
int width = background.width;
int height = background.height;
Texture2D ret = new Texture2D(width, height);
for(int x = ; x < width; x++)
{
for(int y = ; y < height; y++)
{
ret.SetPixel(x, y, background.GetPixel(x, y));
}
} int topWidth = top.width;
int topHeight = top.height;
int x_start = width / - topWidth / ;
int y_start = height / - topHeight / ; for (int x = x_start; x < topWidth + x_start; x++)
{
for (int y = y_start; y < topHeight + y_start; y++)
{
Color bgColor = background.GetPixel(x, y);
Color topColor = top.GetPixel(x - x_start, y - y_start);
ret.SetPixel(x, y, Color.Lerp(bgColor, topColor, topColor.a/1f));
}
}
ret.Apply();
return ret;
}

tip: the background and top texture need can readable.

上一篇:Java泛型的协变与逆变


下一篇:Kotlin泛型与协变及逆变原理剖析