Thanks for the suggestion, but I did try that. Well, i think I did. The only way I could see to change it was via an asset post processor during import, so I think it actually changed. (Edit: Found it under 'Advanced' texture type, but still doesn't fix it.)
Also, do you have excess alpha pixels around your sprite? I figured this setting only helped in that case.
Okay, I am close.
I disabled the 'rotate' flag I have been using in SpriteAttacher. Now, the sprite is rotated 90 degrees again, but the scaling looks to be correct.
When rotating does happen, the mesh itself is not rotated, only the UVs. This means it is placing an upright UV onto a rotated mesh, resulting in the stretching.
So I have to figure out how to deal with this rotation better. Hopefully without rotating all of my sprite assets...
I added the 'rotated = true' again, so the UVs are rotated. On the attachment, I also flipped the width and the height, and it now seems to be working. This hack feels so dirty, but I may stick with it.
//do some math and assign UVs and sizes
attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
attachment.RendererObject = atlasRegion;
attachment.SetColor(Color.white);
attachment.ScaleX = 1;
attachment.ScaleY = 1;
//attachment.RegionOffsetX = sprite.rect.width * (0.5f - Mathf.InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit;
//attachment.RegionOffsetY = sprite.rect.height * (0.5f - Mathf.InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit;
attachment.RegionOffsetX = offset.x;
attachment.RegionOffsetY = offset.y;
attachment.RegionOffsetY = offset.y;
// START: ROTATION FIX
// attachment.Width = size.y;
// attachment.Height = size.x;
attachment.Width = size.y;
attachment.Height = size.x;
// END: ROTATION FIX
attachment.RegionWidth = size.x;
attachment.RegionHeight = size.y;
attachment.RegionOriginalWidth = size.x;
attachment.RegionOriginalHeight = size.y;
attachment.UpdateOffset();
Unfortunately my pivots are still totally messed up. I can't tell if it's due to how I set up my skeleton, or if it is just more bugs galore with Unity integration.
Finally, I think I have it working. I reverted all changes I was trying out, and ended up with just one line change. We'll see if it breaks anything down the line, but it is working for now I think.
//TODO: make sure this rotation thing actually works
bool rotated = false;
if (sprite.packed)
{
rotated = sprite.packingRotation == SpritePackingRotation.Any;
}
//do some math and assign UVs and sizes
attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
attachment.RendererObject = atlasRegion;
attachment.SetColor(Color.white);
attachment.ScaleX = 1;
attachment.ScaleY = 1;
attachment.RegionOffsetX = sprite.rect.width * (0.5f - Mathf.InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit;
attachment.RegionOffsetY = sprite.rect.height * (0.5f - Mathf.InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit;
attachment.Rotation = -90; // <
---
New line, force the attachment rotation
attachment.Width = size.x;
attachment.Height = size.y;
attachment.RegionWidth = size.x;
attachment.RegionHeight = size.y;
attachment.RegionOriginalWidth = size.x;
attachment.RegionOriginalHeight = size.y;
attachment.UpdateOffset();