Hello, i want to change all item wearing at my character by other Unity sprite(like a shop). i just found script Mix-n-Match example and it work well with skeletonAnimation. But when i change it with Skeletongraphic it show issue like this(the gun not show right). Can someone help me to do it right
here are my code :
public class MixAndMatchExample : MonoBehaviour {
[SpineSkin] public string templateSkinName = "template";
public Material sourceMaterial;
[Header("Gun")]
public Sprite gunSprite;
[SpineSlot] public string gunSlot;
[SpineAttachment(slotField:"gunSlot", skinField:"templateSkinName")] public string gunKey = "gun";
[ContextMenu("Combine")]
void Combine () {
SkeletonGraphic skeletonAnimation = GetComponent<SkeletonGraphic>();
Skeleton skeleton = skeletonAnimation.Skeleton;
SkeletonData skeletonData = skeleton.Data;
// Get the template skin.
Skin templateSkin = skeletonData.FindSkin(templateSkinName);
// Prepare the custom skin.
Skin currentEquipsSkin = new Skin("my custom skin");
// Get the gun
int gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
Attachment templateGun = templateSkin.GetAttachment(gunSlotIndex, gunKey);
// Clone the template gun Attachment, and map the sprite onto it.
// This sample uses the sprite and material set in the inspector.
Attachment newGun = templateGun.GetRemappedClone(gunSprite, sourceMaterial); // This has some optional parameters. See below.
//Attachment newGun = templateGun.GetRemappedClone(gunSprite, sourceMaterial, premultiplyAlpha: true, cloneMeshAsLinked: true, useOriginalRegionSize: false); // (Full signature.)
// Add the gun to your new custom skin.
if (newGun != null) currentEquipsSkin.SetAttachment(gunSlotIndex, gunKey, newGun);
// Set and apply the Skin to the skeleton.
skeleton.SetSkin(currentEquipsSkin);
skeleton.SetSlotsToSetupPose();
skeletonAnimation.Update(0);
}
}