iron59

Good day. We're implementing an animated animal character made of several skeleton animations assembled with a single game object parent and with some parts parented to and object with bone follower. We add decorations to the monsters through the use of slots and attachments. The code we use are written in the snippet below:
public void SetDeco(Color decoColor, string attachmentPrefix) {
foreach(Spine.Slot slot in this.spineAnim.Skeleton.Slots) {
if(slot.Data.Name.StartsWith(BodyPartFactory.DECO_SLOT_PREFIX)) {
Spine.Attachment attachment = GetAttachment(attachmentPrefix);
slot.Attachment = attachment;
slot.SetColor(decoColor);
}
}
}

public Spine.Attachment GetAttachment(string attachmentPrefix) {
Spine.Attachment emptyAttachment = null;
Spine.Attachment newAttachment = null;
Spine.Skin skin = this.spineAnim.Skeleton.Skin;

if(skin == null) {
skin = this.spineAnim.Skeleton.Data.DefaultSkin;
}

foreach(KeyValuePair<Spine.Skin.AttachmentKeyTuple, Spine.Attachment> attachment in skin.Attachments) {
if(attachment.Value.Name.StartsWith(attachmentPrefix)) {
if(attachment.Value.Name == BodyPartFactory.DECO_ATTACHMENT_EMPTY) {
emptyAttachment = attachment.Value;
}
else if(attachment.Value.Name.StartsWith(attachmentPrefix)) {
newAttachment = attachment.Value;
}
}
}

if(newAttachment == null) {
newAttachment = emptyAttachment;
}

return newAttachment;
}
Some slots have deco on its name to identify that this slot is meant for the decoration. The attachment prefix is the name of the attachment that should be visible (only one decoration should be used per body part. However, the position of the decorations don't seem to match with the one in the spine editor.

decor placement in runtime.png


decor placement on spine json.png


The slots and attachments for a body part will look something like this.

Slot Inspector.jpg


Basically what I want to do is select the attachment that needs to be enabled for a particular slot. Any suggestions on how to add the attachment to the slot without incorrect positions? Thank you.
iron59
Posts: 17


Return to Unity