You can get a Sprite
from an AtlasRegion via the provided extension method in AttachmentTools
:
using Spine.Unity.AttachmentTools;
void OnGUI () { // or a similar method
Skin skin = ...;
Atlas atlas = ...; // e.g. skeletonAnimation.SkeletonDataAsset.atlasAssets[0].GetAtlas();
foreach (Skin.SkinEntry skinEntry in skin.Attachments) {
string name = skinEntry.Name;
AtlasRegion region = atlas.FindRegion(name);
Sprite sprite = region.ToSprite();
..
}
If this is not an option, you could extract the Attachment's UVs, or regionOffsetX
, regionOffsetY
, regionWidth
, regionHeight
:
foreach (Skin.SkinEntry skinEntry in skin.Attachments) {
var attachment = skinEntry.Attachment;
RegionAttachment regionAttachment = attachment as RegionAttachment;
MeshAttachment meshAttachment = attachment as MeshAttachment;
float[] uvs;
if (regionAttachment != null)
uvs = regionAttachment.UVs; // or get regionOffsetX, regionOffsetY, regionWidth, regionHeight
else if (meshAttachment != null)
uvs = meshAttachment.UVs; // or get regionOffsetX, regionOffsetY, regionWidth, regionHeight
...
And then use the UV coords or regionOffsetX
, regionOffsetY
, regionWidth
, regionHeight
to copy the region pixels to a temporary texture to use with e.g. DrawPreviewTexture
:
https://docs.unity3d.com/ScriptReference/EditorGUI.DrawPreviewTexture.html
Or you could use DrawTexture
, which allows a sourceRect
parameter to define source uv coords.
https://docs.unity3d.com/ScriptReference/Graphics.DrawTexture.html
Note that you then might still run into the problem of packing rotation (which can be 0, 90, 180 or 270 degrees).