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