Эх сурвалжийг харах

[unity] Added `SkeletonGraphic.MeshScale` property to allow access to calculated mesh scale.

Harald Csaszar 2 жил өмнө
parent
commit
cbe0e5433a

+ 2 - 1
CHANGELOG.md

@@ -102,7 +102,8 @@
   * Added support for light cookies at `Universal Render Pipeline/Spine/Sprite` shader.
   * Timeline extension package: An additional Spine preferences parameter `Timeline` - `Default Mix Duration` has been added, setting newly added `SpineAnimationStateClip` clips accordingly, defaults to false. This Spine preferences parameter can be enabled to default to the previous behaviour before this update.
   * Tint Black: Added support for [Tint Black](http://en.esotericsoftware.com/spine-slots#Tint-black) functionality at all Spine URP shaders (2D and 3D shaders) and at all standard pipeline `Spine/Sprite` shaders. This feature can be enabled via the `Tint Black` material parameter in the Inspector. Note: The URP Sprite shaders provided in the Spine URP Shaders extension UPM package require the latest version of the spine-unity runtime (package version 4.1.12, 2023-05-31 or newer) to display the added material parameters in the Inspector GUI.
- 
+  * Added `SkeletonGraphic.MeshScale` property to allow access to calculated mesh scale. `MeshScale` is based on (1) Canvas pixels per unit, and (2) `RectTransform` bounds when using `Layout Scale Mode` other than `None` at `SkeletonGraphic` which scales the skeleton mesh to fit the parent `RectTransform` bounds accordingly.
+
 * **Breaking changes**
   * Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead.
   * `SkeletonGraphic` `OnRebuild` callback delegate is now issued after the skeleton has been initialized, before the `AnimationState` component is initialized. This makes behaviour consistent with `SkeletonAnimation` and `SkeletonMecanim` component behaviour. Use the new callback `OnAnimationRebuild` if you want to receive a callback after the `SkeletonGraphic` `AnimationState` has been initialized.

+ 1 - 1
spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/SpineboyTargetControllerGraphic.cs

@@ -54,7 +54,7 @@ namespace Spine.Unity.Examples {
 			Vector2 localRectPosition;
 			RectTransformUtility.ScreenPointToLocalPointInRectangle(
 				skeletonGraphic.rectTransform, mousePosition, null, out localRectPosition);
-			Vector3 skeletonSpacePoint = localRectPosition / canvas.referencePixelsPerUnit;
+			Vector3 skeletonSpacePoint = localRectPosition / skeletonGraphic.MeshScale;
 			skeletonSpacePoint.x *= skeletonGraphic.Skeleton.ScaleX;
 			skeletonSpacePoint.y *= skeletonGraphic.Skeleton.ScaleY;
 			bone.SetLocalPosition(skeletonSpacePoint);

+ 10 - 8
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs

@@ -67,6 +67,8 @@ namespace Spine.Unity {
 		public bool startingLoop;
 		public float timeScale = 1f;
 		public bool freeze;
+		protected float meshScale = 1f;
+		public float MeshScale { get { return meshScale; } }
 
 		public enum LayoutMode {
 			None = 0,
@@ -780,13 +782,13 @@ namespace Spine.Unity {
 				meshGenerator.BuildMeshWithArrays(currentInstructions, updateTriangles);
 			}
 
-			float scale = (canvas == null) ? 100 : canvas.referencePixelsPerUnit;
+			meshScale = (canvas == null) ? 100 : canvas.referencePixelsPerUnit;
 			if (layoutScaleMode != LayoutMode.None) {
-				scale *= referenceScale;
+				meshScale *= referenceScale;
 				if (!EditReferenceRect)
-					scale *= GetLayoutScale(layoutScaleMode);
+					meshScale *= GetLayoutScale(layoutScaleMode);
 			}
-			meshGenerator.ScaleVertexData(scale);
+			meshGenerator.ScaleVertexData(meshScale);
 			if (OnPostProcessVertices != null) OnPostProcessVertices.Invoke(this.meshGenerator.Buffers);
 
 			Mesh mesh = smartMesh.mesh;
@@ -858,11 +860,11 @@ namespace Spine.Unity {
 		}
 
 		protected void UpdateMeshMultipleCanvasRenderers (SkeletonRendererInstruction currentInstructions) {
-			float scale = (canvas == null) ? 100 : canvas.referencePixelsPerUnit;
+			meshScale = (canvas == null) ? 100 : canvas.referencePixelsPerUnit;
 			if (layoutScaleMode != LayoutMode.None) {
-				scale *= referenceScale;
+				meshScale *= referenceScale;
 				if (!EditReferenceRect)
-					scale *= GetLayoutScale(layoutScaleMode);
+					meshScale *= GetLayoutScale(layoutScaleMode);
 			}
 			// Generate meshes.
 			int submeshCount = currentInstructions.submeshInstructions.Count;
@@ -884,7 +886,7 @@ namespace Spine.Unity {
 				meshGenerator.AddSubmesh(submeshInstructionItem);
 
 				Mesh targetMesh = meshesItems[i];
-				meshGenerator.ScaleVertexData(scale);
+				meshGenerator.ScaleVertexData(meshScale);
 				if (OnPostProcessVertices != null) OnPostProcessVertices.Invoke(this.meshGenerator.Buffers);
 				meshGenerator.FillVertexData(targetMesh);
 				meshGenerator.FillTriangles(targetMesh);