Hello, i have just bought Spine Professional. I use Unity 3D and 2D Toolkit.
Maybe it's a noob question. I have searched about my issue through this forum, but i did not found any topic about this.
Is it possible to use more than one tk2d SpriteCollection in the same Spine Skeleton animation?
I explain my situation. I have imported succesfully tk2d + Spine in my Unity project, created my sprite collection and configure my first character. Now i want to create a new attachment(RegionAttachment) for an slot, and set it normally.
I wrote this function, that i expect to add a new attachment with a sprite of other collection to a skin.
/// <summary>
/// Adds the new attachment.
/// </summary>
/// <param name='skin'>
/// Skin.
/// </param>
/// <param name='collection'>
/// Collection for getting the new region attachment
/// </param>
/// <param name='slotName'>
/// Slot name.
/// </param>
/// <param name='attachmentToCopy'>
/// Attachment to copy all the values
/// </param>
/// <param name='texName'>
/// The name of the image that we want as our attachment(and exists in our collection)
/// </param>
/// <param name='newAttachment'>
/// The name of the new attachment
/// </param>
/// <param name='copyAttachmentProperties'>
/// True = Copy the values of 'attachmentToCopy' Attachment, False = Init values by default
/// </param>
/// <exception cref='ArgumentNullException'>
/// Is thrown when the argument null exception.
/// </exception>
public void AddNewAttachment(Skin skin, tk2dSpriteCollectionData collection, string slotName,string attachmentToCopy, string texName, string newAttachment, bool copyAttachmentProperties){
SpriteCollectionAttachmentLoader spriteCollectionAttachmentLoader = new SpriteCollectionAttachmentLoader(collection);
List<string> attachmentNames;
List<Spine.Attachment> slotAttachments;
int slotIndex = sk.FindSlotIndex(slotName);
//Get a list of attachments
slotAttachments = new List<Attachment>();
skin.FindAttachmentsForSlot(slotIndex,slotAttachments);
//Get a list of attachments names
attachmentNames = new List<string>();
skin.FindNamesForSlot(slotIndex,attachmentNames);
//Create the new attachment
Attachment myNewAtt = spriteCollectionAttachmentLoader.NewRegionAttachment(null,texName,texName);
RegionAttachment myNewRegAtt = myNewAtt as RegionAttachment;
#region IF Copy Attachment properties
if(copyAttachmentProperties){
//Get previous attachment for copying data
Attachment myAtt = GetAttachment(slotAttachments,attachmentToCopy);
if(myAtt == null){
throw new ArgumentNullException ("the attachment " + attachmentToCopy + "doesn't exist for slot " + slotName);
}
//****************************************
RegionAttachment myOldRegAtt = myAtt as RegionAttachment;
//Copy values: x,y,scaleX,scaleY,rotation,width,height and updates offset
CopyAttachmentProperties(myOldRegAtt,ref myNewRegAtt);
}
else{
//Init values: x=0,y=0,scaleX=1,scaleY=1,rotation=0,width=regionOriginalWidth,height=regionOriginalHeight and updates offset
InitRegionAttachment(ref myNewRegAtt);
}
#endregion
skin.AddAttachment(slotIndex, newAttachment, myNewRegAtt);
}
These are the calls and the screenshots of the result:
//As you see, this call is copying the properties...
AddNewAttachment(sk.skin,clothesCollection,"cara2","cara","ojos2","ojoscara",true);
sk.SetAttachment("cara2","cara");
This is the result:

And the other case:
//As you see, this call is not copying the properties...
AddNewAttachment(sk.skin,clothesCollection,"cara2","cara","ojos2","ojoscara",false);
sk.SetAttachment("cara2","cara");
This is the result:

In this case, the new attachment is very big. I think because of setting the width and height to original...
The images are very rare.. because it has no sense. But the idea is to replace the head by new eyes(that it's the only images that exists in the new collection)
These are atlas images:

I used code from this topic.
viewtopic.php?f=7&t=1470&p=7139&hilit=AddAttachment#p7139
I know that i could use Multi atlas, but i wanted to discard the first option first, because i would like to have more control of my atlases. For example, having an atlas for character and body parts, and another atlas for clothes..
Sorry for my bad english 🙁, tell me if you need more information or better explain.
Thanks for any suggestion, help or possible solution 🙂
Hello again,
I am doing some tries with this.
I think the problem is about the draw order...

After the eye change...

I am adding the eyes slot to the draw order list at the first place..
sk.drawOrder.Insert(0,sk.FindSlot(slotName));
sk.SetAttachment(slotName,"newEyes");
Now the image of eyes is cleaner, but it seems that is drawing again the second atlas at background :S.
Note that these new eyes are not definitely mine, just a test eyes...
Anyone knows about this?
I am thinking if it would be better approach creating tk2dsprites and attaching them to bonecomponents.
Because the multiatlas option creates a lot of draw calls.
Maybe i am doing something wrong or the implementation it's more complex that this.
Greetings from Spain =).