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 ];
}
}