Hi there, I posted this extra question in my previous thread regarding skins in Editor and realized it would make more sense to post it here in Unity-Runtime 🙂
So here is my test sample 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();
}
}
Now the beard is actually changing but is rotated by 90°, the sprites are however created from the same "template beard", can somebody tell me what I'm doing wrong ? :/
22 Juin 2017, 16:06
Okay, so I've been messing around a little bit with my Spine project and it turns out some bones had "weird" 90° rotation in Local Space, I compensate it to reset it to zero and now the rotation problem is gone ! :party:
But now the sprite is not correctly aligned... Though I'm sure the new sprite is exactly the same size :bang:
Also, the sprite is not deforming as the mesh it's supposed to be.
I'm really lost in this whole thing :/