|
@@ -33,7 +33,9 @@
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
+
|
|
|
namespace Spine.Unity {
|
|
|
+ using AxisOrientation = BoneFollower.AxisOrientation;
|
|
|
|
|
|
#if NEW_PREFAB_SYSTEM
|
|
|
[ExecuteAlways]
|
|
@@ -66,6 +68,11 @@ namespace Spine.Unity {
|
|
|
public bool followLocalScale = false;
|
|
|
public bool followXYPosition = true;
|
|
|
public bool followZPosition = true;
|
|
|
+ [Tooltip("Applies when 'Follow Skeleton Flip' is disabled but 'Follow Bone Rotation' is enabled."
|
|
|
+ + " When flipping the skeleton by scaling its Transform, this follower's rotation is adjusted"
|
|
|
+ + " instead of its scale to follow the bone orientation. When one of the axes is flipped, "
|
|
|
+ + " only one axis can be followed, either the X or the Y axis, which is selected here.")]
|
|
|
+ public AxisOrientation maintainedAxisOrientation = AxisOrientation.XAxis;
|
|
|
|
|
|
[System.NonSerialized] public Bone bone;
|
|
|
|
|
@@ -134,6 +141,7 @@ namespace Spine.Unity {
|
|
|
if (canvas == null) canvas = skeletonGraphic.GetComponentInParent<Canvas>();
|
|
|
float scale = canvas != null ? canvas.referencePixelsPerUnit : 100.0f;
|
|
|
|
|
|
+ float additionalFlipScale = 1;
|
|
|
if (skeletonTransformIsParent) {
|
|
|
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
|
|
thisTransform.localPosition = new Vector3(followXYPosition ? bone.worldX * scale : thisTransform.localPosition.x,
|
|
@@ -149,25 +157,38 @@ namespace Spine.Unity {
|
|
|
targetWorldPosition.y = thisTransform.position.y;
|
|
|
}
|
|
|
|
|
|
- float boneWorldRotation = bone.WorldRotationX;
|
|
|
-
|
|
|
+ Vector3 skeletonLossyScale = skeletonTransform.lossyScale;
|
|
|
Transform transformParent = thisTransform.parent;
|
|
|
- if (transformParent != null) {
|
|
|
- Matrix4x4 m = transformParent.localToWorldMatrix;
|
|
|
- if (m.m00 * m.m11 - m.m01 * m.m10 < 0) // Determinant2D is negative
|
|
|
+ Vector3 parentLossyScale = transformParent != null ? transformParent.lossyScale : Vector3.one;
|
|
|
+ if (followBoneRotation) {
|
|
|
+ float boneWorldRotation = bone.WorldRotationX;
|
|
|
+
|
|
|
+ if ((skeletonLossyScale.x * skeletonLossyScale.y) < 0)
|
|
|
boneWorldRotation = -boneWorldRotation;
|
|
|
- }
|
|
|
|
|
|
- if (followBoneRotation) {
|
|
|
+ if (followSkeletonFlip || maintainedAxisOrientation == AxisOrientation.XAxis) {
|
|
|
+ if ((skeletonLossyScale.x * parentLossyScale.x < 0))
|
|
|
+ boneWorldRotation += 180f;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if ((skeletonLossyScale.y * parentLossyScale.y < 0))
|
|
|
+ boneWorldRotation += 180f;
|
|
|
+ }
|
|
|
+
|
|
|
Vector3 worldRotation = skeletonTransform.rotation.eulerAngles;
|
|
|
- thisTransform.SetPositionAndRotation(targetWorldPosition, Quaternion.Euler(worldRotation.x, worldRotation.y, skeletonTransform.rotation.eulerAngles.z + boneWorldRotation));
|
|
|
+ if (followLocalScale && bone.scaleX < 0) boneWorldRotation += 180f;
|
|
|
+ thisTransform.SetPositionAndRotation(targetWorldPosition, Quaternion.Euler(worldRotation.x, worldRotation.y, worldRotation.z + boneWorldRotation));
|
|
|
} else {
|
|
|
thisTransform.position = targetWorldPosition;
|
|
|
}
|
|
|
+
|
|
|
+ additionalFlipScale = Mathf.Sign(skeletonLossyScale.x * parentLossyScale.x
|
|
|
+ * skeletonLossyScale.y * parentLossyScale.y);
|
|
|
}
|
|
|
|
|
|
Vector3 localScale = followLocalScale ? new Vector3(bone.scaleX, bone.scaleY, 1f) : new Vector3(1f, 1f, 1f);
|
|
|
- if (followSkeletonFlip) localScale.y *= Mathf.Sign(bone.skeleton.ScaleX * bone.skeleton.ScaleY);
|
|
|
+ if (followSkeletonFlip)
|
|
|
+ localScale.y *= Mathf.Sign(bone.skeleton.ScaleX * bone.skeleton.ScaleY) * additionalFlipScale;
|
|
|
thisTransform.localScale = localScale;
|
|
|
}
|
|
|
|