Hi!
I am making a skin system and I want to preview the skins. For that, I create skin cards that have the skin id that then calls a method to change the skin.
A skin is based on many parts (body, helmet, jetpack, and jetpack trails)
If I click the card, I can see the new skin updated but sends later, the skin disappear and the default one appear again.
The default skin is a Skin that I get from a json (a string array with the skins ids) and I am using the same code as when I change skins.
This is an example of the code to change a full body skin (body and helmet/face).
`
public void SwitchFullBodySkin(string bodySkinSelected, string helmetSkinSelected)
{
currentBodySkin = bodySkinSelected;
currentHelmet = helmetSkinSelected;
Skeleton skeleton = null;
if (GetComponent<SkeletonAnimation>())
{
SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
}
else if (GetComponent<SkeletonGraphic>())
{
SkeletonGraphic skeletonGraphic = GetComponent<SkeletonGraphic>();
skeleton = skeletonGraphic.Skeleton;
}
SkeletonData skeletonData = skeleton.Data;
Skin newSkin = new Skin("New Skin");
newSkin.AddSkin(skeletonData.FindSkin(bodySkinSelected));
newSkin.AddSkin(skeletonData.FindSkin(helmetSkinSelected));
newSkin.AddSkin(skeletonData.FindSkin(currentJetpack));
newSkin.AddSkin(skeletonData.FindSkin(currentJetpackTrail));
// Set and apply the Skin to the skeleton.
skeleton.SetSkin(newSkin);
skeleton.SetSlotsToSetupPose();
if (GetComponent<SkeletonAnimation>())
{
SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation>();
skeletonAnimation.AnimationState.Apply(skeleton);
}
else if (GetComponent<SkeletonGraphic>())
{
SkeletonGraphic skeletonGraphic = GetComponent<SkeletonGraphic>();
skeletonGraphic.AnimationState.Apply(skeleton);
}
}
`
AND I am not starting any animation runtime, I am just using the initial animation that I can set on the SkeletonAnimation / Skeleton Graphic option.
VIDEO