I'm trying to use a spine atlas asset in Unity to attach a region to a slot. The skeleton.SetAttachments has no overload method that takes an attachment only "string, string". I'm sure this has been answered before but after looking around for an hour or so I can't seem to get the attachment to render on screen.
My code:
public static void LinkSprite(Skeleton skeleton, string targetSlot, string spriteName ) {
LoadAtlas();
RegionAttachment attachment = GetAttachment( spriteName );
skeleton.FindSlot( targetSlot ).attachment = attachment;
}
static RegionAttachment GetAttachment(string spriteName ) {
string path = "Equipment/" + spriteName;
AtlasRegion region = equipmentAtlas.GetAtlas().FindRegion( path );
if ( region == null ) throw new System.ArgumentException( string.Format( "Region not found in atlas: {0} (region attachment: {1})", path, spriteName ) );
RegionAttachment attachment = new RegionAttachment( path );
attachment.RendererObject = region;
attachment.SetUVs( region.u, region.v, region.u2, region.v2, region.rotate );
attachment.regionOffsetX = region.offsetX;
attachment.regionOffsetY = region.offsetY;
attachment.regionWidth = region.width;
attachment.regionHeight = region.height;
attachment.regionOriginalWidth = region.originalWidth;
attachment.regionOriginalHeight = region.originalHeight;
return attachment;
}
Is there an easier built-in method to convert an AtlasRegion to Attachment to Slot?