Hello! Pharah, can you tell please how to change custom skin programmatically? So, I can set up targets slots and attachments in inspector and it works fine with Start(), but I need learn how to change it on other events.
I found how to call CustomSkin component (linked to spine character) from other object, but I have no idea what to write for changing target slot etc.
Thanks
Hello! I found solution, I just modified CustomSkin like that:
using UnityEngine;
using Spine;
using Spine.Unity;
public class PickClothes : MonoBehaviour {
private GameObject player;
[System.Serializable]
public class SkinPair
{
[SpineAttachment(currentSkinOnly: false, returnAttachmentPath: true, dataField: "skinSource")]
[UnityEngine.Serialization.FormerlySerializedAs("sourceAttachment")]
public string sourceAttachmentPath;
public string targetSlot;
public string targetAttachment;
}
SkeletonRenderer skeletonRenderer;
public Skin customSkin;
public SkinPair[] skinItems;
public SkeletonDataAsset skinSource;
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
skeletonRenderer = player.GetComponentInChildren<SkeletonRenderer>();
customSkin = new Skin("CustomSkin");
}
void OnMouseDown()
{
Skeleton skeleton = skeletonRenderer.skeleton;
foreach (var pair in skinItems)
{
var attachment = SpineAttachment.GetAttachment(pair.sourceAttachmentPath, skinSource);
customSkin.AddAttachment(skeleton.FindSlotIndex(pair.targetSlot), pair.targetAttachment, attachment);
}
skeleton.SetSkin(customSkin);
}
}
and now I can put this script to some another object, set up skin source and manually write target slot & target attachment and it works, skin part changed when clicking object. The reason I need to rewrite custom skin array is error "Must have reference to a SkeletonDataAsset" when this script put to another object