Browse Source

[unity] Fixed duplicated SkeletonUtilityBones not following properly. Closes #1536.

Harald Csaszar 5 years ago
parent
commit
f3bcd6e28f

+ 24 - 3
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs

@@ -128,12 +128,30 @@ namespace Spine.Unity {
 		public delegate void SkeletonUtilityDelegate ();
 		public event SkeletonUtilityDelegate OnReset;
 		public Transform boneRoot;
+		/// <summary>
+		/// If true, <see cref="Skeleton.ScaleX"/> and <see cref="Skeleton.ScaleY"/> are followed
+		/// by 180 degree rotation. If false, negative Transform scale is used.
+		/// Note that using negative scale is consistent with previous behaviour (hence the default),
+		/// however causes serious problems with rigidbodies and physics. Therefore, it is recommended to
+		/// enable this parameter where possible. When creating hinge chains for a chain of skeleton bones
+		/// via <see cref="SkeletonUtilityBone"/>, it is mandatory to have <c>flipBy180DegreeRotation</c> enabled.
+		/// </summary>
+		public bool flipBy180DegreeRotation = false;
 
 		void Update () {
 			var skeleton = skeletonRenderer.skeleton;
 			if (skeleton != null && boneRoot != null) {
-				boneRoot.localScale = new Vector3(skeleton.ScaleX, skeleton.ScaleY, 1f);
-			}
+
+				if (flipBy180DegreeRotation) {
+					boneRoot.localScale = new Vector3(Mathf.Abs(skeleton.ScaleX), Mathf.Abs(skeleton.ScaleY), 1f);
+					boneRoot.eulerAngles = new Vector3(skeleton.ScaleY > 0 ? 0 : 180,
+																	skeleton.ScaleX > 0 ? 0 : 180,
+																	0);
+				}
+				else {
+					boneRoot.localScale = new Vector3(skeleton.ScaleX, skeleton.ScaleY, 1f);
+				}
+			 }
 		}
 
 		[HideInInspector] public SkeletonRenderer skeletonRenderer;
@@ -233,7 +251,10 @@ namespace Spine.Unity {
 				var boneComponents = this.boneComponents;
 				for (int i = 0, n = boneComponents.Count; i < n; i++) {
 					var b = boneComponents[i];
-					if (b.bone == null) continue;
+					if (b.bone == null) {
+						b.DoUpdate(SkeletonUtilityBone.UpdatePhase.Local);
+						if (b.bone == null) continue;
+					}
 					hasOverrideBones |= (b.mode == SkeletonUtilityBone.Mode.Override);
 					hasConstraints |= constraintTargets.Contains(b.bone);
 				}