Hi,
I have a character with a few items (hat, glasses, necklace, boots and weapon) to swop and the character (head, body, arms and legs) itself can change color skin (blue, green, etc.).
I start with a default skin, with no attachments to the skin slots (and thus no color), and with default items attachments to the items slots;
The skin is changed via the method here below and on Start() the blue color will be passed in.
public void ApplySkin(string str)
{
skeleton.SetSkin (str);
skeleton.SetSlotsToSetupPose(); //use the pose from setup pose
skeletonAnimation.AnimationState.Apply(skeleton); //make sure the attachments from your currently playing animation are applied
}
The changing of skins works fine. And the mix and match of items works fine too.
But when I firstly change a skin, and then do an item swop, the skin changes back to the previous one. If I then do more item swops, this skin stays put. If I then change the skin again and do an item swop, it does it again: it goes back to previous skin and stays like that the following item swops. And so on.
Here's my code for an item swop:
void ApplyNewAttachment(Sprite spr, string slot, string key)
{
// STEP 0: PREPARE SKINS
// Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected.
//customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine.
customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin.
templateSkin = skeleton.Data.FindSkin(templateAttachmentsSkin);
// STEP 1: "EQUIP" ITEMS USING SPRITES
// STEP 1.1 Find the original/template attachment.
// Step 1.2 Get a clone of the original/template attachment.
// Step 1.3 Apply the Sprite image to the clone.
// Step 1.4 Add the remapped clone to the new custom skin.
slotIndex = skeleton.FindSlotIndex(slot);// You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster
Attachment templateItem = templateSkin.GetAttachment(slotIndex, key); // STEP 1.1
Attachment newItem = templateItem.GetRemappedClone(spr, sourceMaterial); // STEP 1.2 - 1.3
if (newItem != null) customSkin.SetAttachment(slotIndex, key, newItem); // STEP 1.4
skeleton.SetSkin(customSkin); // Just use the custom skin directly.
//skeleton.SetSlotsToSetupPose(); //use the pose from setup pose
Slot slotToSetUpPose = skeleton.Slots.Items[slotIndex];
slotToSetUpPose.SetToSetupPose(); // Just affect the one slot.
skeletonAnimation.Update(0); // Use the pose in the currently active animation.
}
I tried a few things and still fail to see why I'm getting this result.
What am I missing?
Cheers,
Nikola