浏览代码

[unity] `Attachment.GetRemappedClone(Sprite)` method now provides an additional optional parameter `useOriginalRegionScale`.

Harald Csaszar 4 年之前
父节点
当前提交
700e316e57
共有 2 个文件被更改,包括 12 次插入2 次删除
  1. 1 0
      CHANGELOG.md
  2. 11 2
      spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs

+ 1 - 0
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.
   * 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 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.
   * 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**
 * **Changes of default values**
   * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.
   * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.

+ 11 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs

@@ -86,16 +86,25 @@ namespace Spine.Unity.AttachmentTools {
 		/// <param name="pivotShiftsMeshUVCoords">If <c>true</c> and the original Attachment is a MeshAttachment, then
 		/// <param name="pivotShiftsMeshUVCoords">If <c>true</c> 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
 		///	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.</param>
 		///	any case when the original Attachment is a MeshAttachment.</param>
+		///	<param name="useOriginalRegionScale">If <c>true</c> 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.</param>
 		public static Attachment GetRemappedClone (this Attachment o, Sprite sprite, Material sourceMaterial,
 		public static Attachment GetRemappedClone (this Attachment o, Sprite sprite, Material sourceMaterial,
 			bool premultiplyAlpha = true, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false,
 			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 } );
 			var atlasRegion = premultiplyAlpha ? sprite.ToAtlasRegionPMAClone(sourceMaterial) : sprite.ToAtlasRegion(new Material(sourceMaterial) { mainTexture = sprite.texture } );
 			if (!pivotShiftsMeshUVCoords && o is MeshAttachment) {
 			if (!pivotShiftsMeshUVCoords && o is MeshAttachment) {
 				// prevent non-central sprite pivot setting offsetX/Y and shifting uv coords out of mesh bounds
 				// prevent non-central sprite pivot setting offsetX/Y and shifting uv coords out of mesh bounds
 				atlasRegion.offsetX = 0;
 				atlasRegion.offsetX = 0;
 				atlasRegion.offsetY = 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);
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>