From 700e316e571aa1ec1f8c910de290df9135f774ec Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 30 Apr 2021 18:01:04 +0200 Subject: [PATCH] [unity] `Attachment.GetRemappedClone(Sprite)` method now provides an additional optional parameter `useOriginalRegionScale`. --- CHANGELOG.md | 1 + .../Utility/AttachmentCloneExtensions.cs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59d655eca..9e6e33b52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -258,6 +258,7 @@ * Added an example component `RootMotionDeltaCompensation` located in `Spine Examples/Scripts/Sample Components` which can be used for applying simple delta compensation. You can enable and disable the component to toggle delta compensation of the currently playing animation on and off. * Root motion delta compensation now allows to only adjust X or Y components instead of both. Adds two parameters to `SkeletonRootMotionBase.AdjustRootMotionToDistance()` which default to adjusting both X and Y as before. The `RootMotionDeltaCompensation` example component exposes these parameters as public attributes. * Root motion delta compensation now allows to also add translation root motion to e.g. adjust a horizontal jump upwards or downwards over time. This is necessary because a Y root motion of zero cannot be scaled to become non-zero. + * `Attachment.GetRemappedClone(Sprite)` method now provides an additional optional parameter `useOriginalRegionScale`. When set to `true`, the replaced attachment's scale is used instead of the Sprite's `Pixel per Unity` setting, allowing for more consistent scaling. *Note:* When remapping Sprites, be sure to set the Sprite's `Mesh Type` to `Full Rect` and not `Tight`, otherwise the scale will be wrong. * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs index 52c4ba1ad..2629c41f9 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs @@ -86,16 +86,25 @@ namespace Spine.Unity.AttachmentTools { /// If true and the original Attachment is a MeshAttachment, then /// a non-central sprite pivot will shift uv coords in the opposite direction. Vertices will not be offset in /// any case when the original Attachment is a MeshAttachment. + /// If true and the original Attachment is a RegionAttachment, then + /// the original region's scale value is used instead of the Sprite's pixels per unit property. Since uniform scale is used, + /// x scale of the original attachment (width scale) is used, scale in y direction (height scale) is ignored. public static Attachment GetRemappedClone (this Attachment o, Sprite sprite, Material sourceMaterial, bool premultiplyAlpha = true, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false, - bool pivotShiftsMeshUVCoords = true) { + bool pivotShiftsMeshUVCoords = true, bool useOriginalRegionScale = false) { var atlasRegion = premultiplyAlpha ? sprite.ToAtlasRegionPMAClone(sourceMaterial) : sprite.ToAtlasRegion(new Material(sourceMaterial) { mainTexture = sprite.texture } ); if (!pivotShiftsMeshUVCoords && o is MeshAttachment) { // prevent non-central sprite pivot setting offsetX/Y and shifting uv coords out of mesh bounds atlasRegion.offsetX = 0; atlasRegion.offsetY = 0; } - return o.GetRemappedClone(atlasRegion, cloneMeshAsLinked, useOriginalRegionSize, 1f/sprite.pixelsPerUnit); + float scale = 1f / sprite.pixelsPerUnit; + if (useOriginalRegionScale) { + var regionAttachment = o as RegionAttachment; + if (regionAttachment != null) + scale = regionAttachment.width / regionAttachment.regionOriginalWidth; + } + return o.GetRemappedClone(atlasRegion, cloneMeshAsLinked, useOriginalRegionSize, scale); } ///