Thanks Nate, it seems to work pretty well (even if I had to rearrange a little bit).
But even with a skin correctly set in my spine project I can't get to change attachment properly in runtime :/
In this example I want to change the dwarf beard from a unity sprite (picked up in a list), all the beards are just variations of color, made from the exact same sprite that the one used in the skin (same size, rotation etc)
Here is my test code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using Spine.Unity.Modules.AttachmentTools;
public class SkinManager : MonoBehaviour
{
public Sprite[] beardSpriteList;
[SpineSlot] public string beardSlot;
public Skin newSkin;
public Skeleton skeleton;
// Use this for initialization
void Start()
{
beardSpriteList = Resources.LoadAll<Sprite>("Skins/Beards");
var skeletonAnimation = GetComponentInChildren<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
// All attachment changes will be applied to the skin. We use a clone so other instances will not be affected.
newSkin = skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState);
StartCoroutine("TestChange");
}
// Update is called once per frame
void Update()
{
}
public IEnumerator TestChange()
{
yield return new WaitForSeconds(1);
RegionAttachment newBeard = beardSpriteList[1].ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));
int beardSlotIndex = skeleton.FindSlotIndex(beardSlot);
var tete = skeleton.GetAttachment(beardSlotIndex,"tete"); // tête is head in french ^^
var newTete = tete.GetClone(true);
newTete = beardSpriteList[1].ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));
string newBeardName = beardSpriteList[1].name;
Debug.Log("equiping :" + newBeardName);
newSkin.AddAttachment(beardSlotIndex, newBeardName, newTete);
skeleton.SetSkin(newSkin);
skeleton.SetToSetupPose();
skeleton.SetAttachment(beardSlot, newBeardName);
Resources.UnloadUnusedAssets();
}
}
The beard actually changes, but seems to be weirdly rotated :/
What am I doing wrong ?