|
@@ -79,6 +79,16 @@ namespace Spine.Unity {
|
|
[Tooltip("Follows the target bone's local or uniform world scale. Note: If world scale is non-uniform/skewed, you will receive incorrect results with WorldUniform.")]
|
|
[Tooltip("Follows the target bone's local or uniform world scale. Note: If world scale is non-uniform/skewed, you will receive incorrect results with WorldUniform.")]
|
|
public ScaleMode followScaleMode = ScaleMode.Local;
|
|
public ScaleMode followScaleMode = ScaleMode.Local;
|
|
|
|
|
|
|
|
+ public enum AxisOrientation {
|
|
|
|
+ XAxis = 1,
|
|
|
|
+ YAxis
|
|
|
|
+ }
|
|
|
|
+ [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;
|
|
|
|
+
|
|
[UnityEngine.Serialization.FormerlySerializedAs("resetOnAwake")]
|
|
[UnityEngine.Serialization.FormerlySerializedAs("resetOnAwake")]
|
|
public bool initializeOnAwake = true;
|
|
public bool initializeOnAwake = true;
|
|
#endregion
|
|
#endregion
|
|
@@ -151,6 +161,7 @@ namespace Spine.Unity {
|
|
}
|
|
}
|
|
|
|
|
|
Transform thisTransform = this.transform;
|
|
Transform thisTransform = this.transform;
|
|
|
|
+ float additionalFlipScale = 1;
|
|
if (skeletonTransformIsParent) {
|
|
if (skeletonTransformIsParent) {
|
|
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
|
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
|
|
thisTransform.localPosition = new Vector3(followXYPosition ? bone.worldX : thisTransform.localPosition.x,
|
|
thisTransform.localPosition = new Vector3(followXYPosition ? bone.worldX : thisTransform.localPosition.x,
|
|
@@ -178,16 +189,24 @@ namespace Spine.Unity {
|
|
targetWorldPosition.y = thisTransform.position.y;
|
|
targetWorldPosition.y = thisTransform.position.y;
|
|
}
|
|
}
|
|
|
|
|
|
- float boneWorldRotation = bone.WorldRotationX;
|
|
|
|
-
|
|
|
|
|
|
+ Vector3 skeletonLossyScale = skeletonTransform.lossyScale;
|
|
Transform transformParent = thisTransform.parent;
|
|
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;
|
|
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;
|
|
Vector3 worldRotation = skeletonTransform.rotation.eulerAngles;
|
|
if (followScale &&
|
|
if (followScale &&
|
|
(followScaleMode == ScaleMode.Local ?
|
|
(followScaleMode == ScaleMode.Local ?
|
|
@@ -197,13 +216,18 @@ namespace Spine.Unity {
|
|
} else {
|
|
} else {
|
|
thisTransform.position = targetWorldPosition;
|
|
thisTransform.position = targetWorldPosition;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ additionalFlipScale = Mathf.Sign(skeletonLossyScale.x * parentLossyScale.x
|
|
|
|
+ * skeletonLossyScale.y * parentLossyScale.y);
|
|
}
|
|
}
|
|
|
|
|
|
Vector3 localScale = followScale ? (followScaleMode == ScaleMode.Local ?
|
|
Vector3 localScale = followScale ? (followScaleMode == ScaleMode.Local ?
|
|
new Vector3(bone.scaleX, bone.scaleY, 1f) :
|
|
new Vector3(bone.scaleX, bone.scaleY, 1f) :
|
|
new Vector3(bone.WorldScaleX, bone.WorldScaleY, 1f)) :
|
|
new Vector3(bone.WorldScaleX, bone.WorldScaleY, 1f)) :
|
|
new Vector3(1f, 1f, 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;
|
|
thisTransform.localScale = localScale;
|
|
}
|
|
}
|
|
}
|
|
}
|