fix spritesheet scaler incorrectly setting pivots

This commit is contained in:
minenice55 2024-01-19 20:51:14 -05:00
parent f68192e6e2
commit 2b30b7de97
2 changed files with 7 additions and 3 deletions

View file

@ -77,7 +77,8 @@ public class SpritesheetScaler : EditorWindow
for (int i = 0; i < ti1.spritesheet.Length; i++)
{
SpriteMetaData d = ti1.spritesheet[i];
Vector2 oldPivot = Rect.NormalizedToPoint(d.rect, d.pivot) * multiplier;
// pivot relative to the origin of the rect in pixels
Vector2 oldPivot = new Vector2(d.pivot.x * d.rect.width, d.pivot.y * d.rect.height);
d.rect = ScaleRect(d.rect, multiplier, inflateX, inflateY);
d.border.x += d.border.x > 0 ? inflateX : 0;
@ -85,10 +86,12 @@ public class SpritesheetScaler : EditorWindow
d.border.z += d.border.z > 0 ? inflateX : 0;
d.border.w += d.border.w > 0 ? inflateY : 0;
if (inflateX > 0 || inflateY > 0)
if (d.alignment != (int)SpriteAlignment.Center && (inflateX > 0 || inflateY > 0))
{
d.alignment = (int)SpriteAlignment.Custom;
d.pivot = Rect.PointToNormalized(d.rect, oldPivot);
oldPivot += new Vector2(inflateX, inflateY);
Vector2 newPivot = oldPivot * multiplier;
d.pivot = new Vector2(newPivot.x / d.rect.width, newPivot.y / d.rect.height);
}
d.border *= multiplier;

View file

@ -23,5 +23,6 @@ MonoBehaviour:
- Assets/Scripts/Games/Minigame.cs
- Assets/Scripts/Games/FanClub/FanClub.cs
- Assets/Scripts/GameManager.cs
- Assets/Editor/SpritesheetScaler.cs
PathsToSkipImportEvent: []
PathsToIgnoreOverwriteSettingOnAttribute: []