diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f08549f8..0bb3f751f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -246,6 +246,7 @@ * Prefabs containing `SkeletonRenderer`, `SkeletonAnimation` and `SkeletonMecanim` now provide a proper Editor preview, including the preview thumbnail. * `SkeletonRenderer` (and subclasses`SkeletonAnimation` and `SkeletonMecanim`) now provide a property `Advanced - Fix Prefab Override MeshFilter`, which when enabled fixes the prefab always being marked as changed. It sets the MeshFilter's hide flags to `DontSaveInEditor`. Unfortunately this comes at the cost of references to the `MeshFilter` by other components being lost, therefore this parameter defaults to `false` to keep the safe existing behaviour. * `BoundingBoxFollower` and `BoundingBoxFollowerGraphic` now provide previously missing `usedByEffector` and `usedByComposite` parameters to be set at all generated colliders. + * `BoneFollower` and `BoneFollowerGraphic` now provide an additional `Follow Parent World Scale` parameter to allow following simple scale of parent bones (rotated/skewed scale can't be supported). * **Changes of default values** diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerGraphicInspector.cs index 2339597fc..d42067c69 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerGraphicInspector.cs @@ -40,7 +40,7 @@ namespace Spine.Unity.Editor { public class BoneFollowerGraphicInspector : Editor { SerializedProperty boneName, skeletonGraphic, followXYPosition, followZPosition, followBoneRotation, - followLocalScale, followSkeletonFlip, maintainedAxisOrientation; + followLocalScale, followParentWorldScale, followSkeletonFlip, maintainedAxisOrientation; BoneFollowerGraphic targetBoneFollower; bool needsReset; @@ -77,6 +77,7 @@ namespace Spine.Unity.Editor { followXYPosition = serializedObject.FindProperty("followXYPosition"); followZPosition = serializedObject.FindProperty("followZPosition"); followLocalScale = serializedObject.FindProperty("followLocalScale"); + followParentWorldScale = serializedObject.FindProperty("followParentWorldScale"); followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip"); maintainedAxisOrientation = serializedObject.FindProperty("maintainedAxisOrientation"); @@ -172,6 +173,7 @@ namespace Spine.Unity.Editor { EditorGUILayout.PropertyField(followXYPosition); EditorGUILayout.PropertyField(followZPosition); EditorGUILayout.PropertyField(followLocalScale); + EditorGUILayout.PropertyField(followParentWorldScale); EditorGUILayout.PropertyField(followSkeletonFlip); if ((followSkeletonFlip.hasMultipleDifferentValues || followSkeletonFlip.boolValue == false) && (followBoneRotation.hasMultipleDifferentValues || followBoneRotation.boolValue == true)) { diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerInspector.cs index e9051719b..448df808a 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/BoneFollowerInspector.cs @@ -38,12 +38,12 @@ namespace Spine.Unity.Editor { [CustomEditor(typeof(BoneFollower)), CanEditMultipleObjects] public class BoneFollowerInspector : Editor { SerializedProperty boneName, skeletonRenderer, followXYPosition, followZPosition, followBoneRotation, - followLocalScale, followSkeletonFlip, maintainedAxisOrientation; + followLocalScale, followParentWorldScale, followSkeletonFlip, maintainedAxisOrientation; BoneFollower targetBoneFollower; bool needsReset; #region Context Menu Item - [MenuItem("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")] + [MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")] static void AddBoneFollowerGameObject (MenuCommand cmd) { var skeletonRenderer = cmd.context as SkeletonRenderer; var go = EditorInstantiation.NewGameObject("New BoneFollower", true); @@ -60,7 +60,7 @@ namespace Spine.Unity.Editor { } // Validate - [MenuItem("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject", true)] + [MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject", true)] static bool ValidateAddBoneFollowerGameObject (MenuCommand cmd) { var skeletonRenderer = cmd.context as SkeletonRenderer; return skeletonRenderer.valid; @@ -86,6 +86,7 @@ namespace Spine.Unity.Editor { followXYPosition = serializedObject.FindProperty("followXYPosition"); followZPosition = serializedObject.FindProperty("followZPosition"); followLocalScale = serializedObject.FindProperty("followLocalScale"); + followParentWorldScale = serializedObject.FindProperty("followParentWorldScale"); followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip"); maintainedAxisOrientation = serializedObject.FindProperty("maintainedAxisOrientation"); @@ -178,6 +179,7 @@ namespace Spine.Unity.Editor { EditorGUILayout.PropertyField(followXYPosition); EditorGUILayout.PropertyField(followZPosition); EditorGUILayout.PropertyField(followLocalScale); + EditorGUILayout.PropertyField(followParentWorldScale); EditorGUILayout.PropertyField(followSkeletonFlip); if ((followSkeletonFlip.hasMultipleDifferentValues || followSkeletonFlip.boolValue == false) && (followBoneRotation.hasMultipleDifferentValues || followBoneRotation.boolValue == true)) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollower.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollower.cs index 0ad58e19e..53b23f869 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollower.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollower.cs @@ -67,9 +67,11 @@ namespace Spine.Unity { [Tooltip("Follows the skeleton's flip state by controlling this Transform's local scale.")] public bool followSkeletonFlip = true; - [Tooltip("Follows the target bone's local scale. BoneFollower cannot inherit world/skewed scale because of UnityEngine.Transform property limitations.")] + [Tooltip("Follows the target bone's local scale.")] [UnityEngine.Serialization.FormerlySerializedAs("followScale")] public bool followLocalScale = false; + [Tooltip("Includes the parent bone's lossy world scale. BoneFollower cannot inherit rotated/skewed scale because of UnityEngine.Transform property limitations.")] + public bool followParentWorldScale = false; public enum AxisOrientation { XAxis = 1, @@ -206,10 +208,14 @@ namespace Spine.Unity { * skeletonLossyScale.y * parentLossyScale.y); } - Vector3 localScale = followLocalScale ? new Vector3(bone.ScaleX, bone.ScaleY, 1f) : new Vector3(1f, 1f, 1f); + Bone parentBone = bone.Parent; + Vector3 localScale = new Vector3(1f, 1f, 1f); + if (followParentWorldScale && parentBone != null) + localScale = new Vector3(parentBone.WorldScaleX, parentBone.WorldScaleY, 1f); + if (followLocalScale) + localScale.Scale(new Vector3(bone.ScaleX, bone.ScaleY, 1f)); if (followSkeletonFlip) localScale.y *= Mathf.Sign(bone.Skeleton.ScaleX * bone.Skeleton.ScaleY) * additionalFlipScale; - thisTransform.localScale = localScale; } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs index 283a106ff..daa217919 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs @@ -64,8 +64,10 @@ namespace Spine.Unity { public bool followBoneRotation = true; [Tooltip("Follows the skeleton's flip state by controlling this Transform's local scale.")] public bool followSkeletonFlip = true; - [Tooltip("Follows the target bone's local scale. BoneFollower cannot inherit world/skewed scale because of UnityEngine.Transform property limitations.")] + [Tooltip("Follows the target bone's local scale.")] public bool followLocalScale = false; + [Tooltip("Includes the parent bone's lossy world scale. BoneFollower cannot inherit rotated/skewed scale because of UnityEngine.Transform property limitations.")] + public bool followParentWorldScale = false; public bool followXYPosition = true; public bool followZPosition = true; [Tooltip("Applies when 'Follow Skeleton Flip' is disabled but 'Follow Bone Rotation' is enabled." @@ -185,7 +187,12 @@ namespace Spine.Unity { * skeletonLossyScale.y * parentLossyScale.y); } - Vector3 localScale = followLocalScale ? new Vector3(bone.ScaleX, bone.ScaleY, 1f) : new Vector3(1f, 1f, 1f); + Bone parentBone = bone.Parent; + Vector3 localScale = new Vector3(1f, 1f, 1f); + if (followParentWorldScale && parentBone != null) + localScale = new Vector3(parentBone.WorldScaleX, parentBone.WorldScaleY, 1f); + if (followLocalScale) + localScale.Scale(new Vector3(bone.ScaleX, bone.ScaleY, 1f)); if (followSkeletonFlip) localScale.y *= Mathf.Sign(bone.Skeleton.ScaleX * bone.Skeleton.ScaleY) * additionalFlipScale; thisTransform.localScale = localScale;