From 193882f2c691c60be79caa9937cb43bbaa32a054 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 15 Dec 2021 16:51:22 +0100 Subject: [PATCH] [unity] `BoneFollower` and `BoneFollowerGraphic` now provide an additional `Follow Parent World Scale` parameter. --- CHANGELOG.md | 1 + .../Components/BoneFollowerGraphicInspector.cs | 4 +++- .../Editor/Components/BoneFollowerInspector.cs | 8 +++++--- .../spine-unity/Components/Following/BoneFollower.cs | 12 +++++++++--- .../Components/Following/BoneFollowerGraphic.cs | 11 +++++++++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f256797f..93078b113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,6 +159,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 21677dcef..b642f77c9 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 a94488425..24ea9dbb2 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 ed76fc339..591c4fbc4 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 6ea4ce3c1..7cdade7d4 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;