Wow, thank you so much for the quick reply, on a Saturday! I am seriously impressed, and you can bet I'll be recommending you guys to every game developer I know, just for your customer support alone.
I tried the new version and it works great for replicating the demo, but in UI. Thank you so much! That said... I'm still having a bit of a problem. It's not a huge problem, mind you. But I figured I'd bring it up.
The main reason for wanting this feature is a "dressing room" UI panel where you put various outfits on the characters. So it would be best to be able to change out attachments to various Unity Sprites multiple times. However, the Mix and Match code only works once. Try to run it again, and all the quads in the mesh are displayed as black rectangles. I found that if you comment out the "Resources.UnloadUnusedAssets()" line, it won't be all black, but the sprite will look like it did in the third picture in my original post.
I tried messing around with this a bunch, but again to no avail. Here's my current code:
public class MixAndMatchUI : MonoBehaviour {
#region Inspector
[Header("From Sprite")]
public Sprite dagger;
public Sprite dagger2;
int currentDagger = 0;
public string daggerName = "dagger";
public string daggerName2 = "dagger2";
[SpineSlot] public string weaponSlot;
#endregion
Spine.Skin mySkin;
ScaledSkeletonGraphic skeletonGraphic;
Spine.Skeleton skeleton;
Shader skeletonShader;
void Start () {
skeletonGraphic = GetComponent<SkeletonGraphic>();
skeleton = skeletonGraphic.Skeleton;
mySkin = skeleton.UnshareSkin(true, false, skeletonGraphic.AnimationState);
skeletonShader = skeletonGraphic.material.shader;
ChangeEquipment();
}
void ChangeEquipment() {
Sprite sprite = currentDagger == 1 ? dagger : dagger2;
string spriteName = currentDagger == 1 ? daggerName : daggerName2;
RegionAttachment newWeapon = sprite.ToRegionAttachmentPMAClone(skeletonShader);
newWeapon.UpdateOffset();
int weaponSlotIndex = skeleton.FindSlotIndex(weaponSlot);
Spine.Skin skin = mySkin;
skin.AddAttachment(weaponSlotIndex, spriteName, newWeapon);
Texture2D runtimeAtlas = null;
Material runtimeMaterial;
skin = skin.GetRepackedSkin("repacked", skeletonShader, out runtimeMaterial, out runtimeAtlas);
skeleton.SetSkin(skin);
skeletonGraphic.OverrideTexture = runtimeAtlas;
skeleton.SetToSetupPose();
skeleton.SetAttachment(weaponSlot, spriteName);
// uncomment this and it will be black boxes after the first call, comment it to show the wrong texture regions
// Resources.UnloadUnusedAssets();
}
public void OnClick() {
currentDagger = (currentDagger + 1) % 2;
ChangeEquipment();
}
}
As you can see, I tried storing the original skin and continually repacking from that, thinking it might help. It did not. To test, I just attached a Button that called OnClick() to the gameobject. What's super weird is that if you just add "OnClick()" after the "ChangeEquipment()" in Start(), it works perfectly!
As I mentioned before, this isn't a huge deal, because I can just destroy and reinstantiate the gameobject every time I want to change its clothes. But that seems inefficient, and quite frankly this behavior is super weird so I figured you might like to know.
Thanks again!