I change skin like this way:
https://zh.esotericsoftware.com/forum/d/26713-skin-repack-can-not-work
I have many different png pictures. I use the following method to change the skins. Each picture acts as a sprite:
public void ChangeAvatar(Sprite sprAvatar, string strTargetSlot,string strTargetAttach)
{
Debug.Log("sprAvatar:" + sprAvatar.name);
var templateSkin = skeleton.Data.FindSkin("default");
int slotIndex = skeleton.Data.FindSlot(strTargetSlot).Index;
Attachment templateAttach = templateSkin.GetAttachment(slotIndex, strTargetAttach); // STEP 1.1
Attachment newAttach = templateAttach.GetRemappedClone(sprAvatar, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.2 - 1.3
if (newAttach != null) customSkin.SetAttachment(slotIndex, strTargetAttach, newAttach); // STEP 1.4
this.skeleton.SetAttachment(strTargetSlot, strTargetAttach);//设置显示新的服装
}
Therefore, each time this method is called, a separate material will be generated:
So I conceived a solution:
Read these images as 2D textures, merge them into a larger texture named "biggerTexture", and store the corresponding UV (position) information.
Assign the UV information of each component in the biggerTexture to a RegionAttachment, and then assign each RegionAttachment to the Spine object. The Spine object will use this biggerTexture as the material texture and display correctly.
Unfortunately, I was unable to complete this process as planned. I only merge the different images into the biggerTexture.
When I create a RegionAttachment, and assign it to the Spine object. There was a problem at this step, resulting in a messed up display of the graphics on my Spine object.
Is my idea feasible? Can you provide the implementation code?