sjyoooon

I put all attachments in the list like below.
Is there any way to get all attachments list in the specific slot via code?
I want to avoid modifying the code whenever I add new weapons.
SkeletonAnimation spine;
Slot weaponSlot;
List <Attachment> weaponAttachmentList = new List<Attachment>();

void Start()
{
initializeWeapon();
}

void initializeWeapon()
{
weaponSlot = spine.skeleton.FindSlot("weapon");

// I want to get all attachments list from weaponSlot and put them in weaponAttachmentList at once
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon0"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon1"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon2"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon3"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon4"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon5"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon6"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon7"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon8"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon9"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon10"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon11"));
weaponAttachmentList.Add(spine.Skeleton.GetAttachment("weapon", "weapons/weapon12"));
}

public void SetWeapon(int weaponIndex)
{
if ( weaponIndex < weaponAttachmentList.Count )
{
weaponSlot.Attachment = weaponAttachmentList[ weaponIndex ];
}
}
sjyoooon
  • Posts: 2

Harald

Yes, you can use skin.GetAttachments (int slotIndex, List<SkinEntry> attachments) to fill the attachments parameter with all SkinEntries at the given slot:
spine-runtimes/Skin.cs at 3.8
Then access SkinEntry.Attachment to get the attachment.
User avatar
Harald

Harri
  • Posts: 2091

sjyoooon

Harald wrote:Yes, you can use skin.GetAttachments (int slotIndex, List<SkinEntry> attachments) to fill the attachments parameter with all SkinEntries at the given slot:
https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-csharp/src/Skin.cs#L116
Then access SkinEntry.Attachment to get the attachment.
It works fine! Thank you.
sjyoooon
  • Posts: 2

Harald

You're welcome. :)
User avatar
Harald

Harri
  • Posts: 2091


Return to Unity