I have an avatar generator where someone can create a custom avatar with layers superimposed. And in order to reuse this image multiple times, i want to merge all layers in one image. Is there any way on unity3D to create this image.
I've already coded that :
atlas = new Texture2D (width, height, TextureFormat.RGBA32, false);
foreach (Sprite s in allSprite) {
atlas.SetPixels (0, 0, atlas.width, atlas.height, s.texture.GetPixels (0, 0, atlas.width, atlas.height));
atlas.Apply ();
}
My problem is to keep the transparency and not erase old layers where pixels are transparent.
The setPixels
method replace old pixels in atlas
by new one.
I can't loop over pixels because of the size of the image (1024*1024) and more than 6 layers.