From 97c5293fb1688d396cfc719639c00dd7ffad6c67 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 5 Jan 2018 14:11:52 +0800 Subject: [PATCH 1/5] [unity] Fix MecanimTranslator clearing incompletely. --- spine-unity/Assets/spine-unity/SkeletonAnimator.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index 5bdbcd0d7..dfe76db59 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -120,17 +120,25 @@ namespace Spine.Unity { readonly List clipInfoCache = new List(); readonly List nextClipInfoCache = new List(); #endif - Animator animator; + Animator animator; public Animator Animator { get { return this.animator; } } public void Initialize (Animator animator, SkeletonDataAsset skeletonDataAsset) { this.animator = animator; + + previousAnimations.Clear(); + animationTable.Clear(); - clipNameHashCodeTable.Clear(); var data = skeletonDataAsset.GetSkeletonData(true); foreach (var a in data.Animations) animationTable.Add(a.Name.GetHashCode(), a); + + clipNameHashCodeTable.Clear(); + #if UNITY_2017_1_OR_NEWER + clipInfoCache.Clear(); + nextClipInfoCache.Clear(); + #endif } public void Apply (Skeleton skeleton) { From 5e563c883d2571dbdd27b4ea0c62e8b28eedf964 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 6 Jan 2018 21:30:37 +0800 Subject: [PATCH 2/5] [unity] Include Unity 5.6 for clipInfoCache API usage. --- spine-unity/Assets/spine-unity/SkeletonAnimator.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index dfe76db59..c9d0c4da6 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -28,7 +28,9 @@ * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -// Contributed by: Mitch Thompson +#if UNITY_5_6_OR_NEWER +#define UNITY_CLIPINFOCACHE +#endif using UnityEngine; using System.Collections.Generic; @@ -116,7 +118,7 @@ namespace Spine.Unity { readonly Dictionary animationTable = new Dictionary(IntEqualityComparer.Instance); readonly Dictionary clipNameHashCodeTable = new Dictionary(AnimationClipEqualityComparer.Instance); readonly List previousAnimations = new List(); - #if UNITY_2017_1_OR_NEWER + #if UNITY_CLIPINFOCACHE readonly List clipInfoCache = new List(); readonly List nextClipInfoCache = new List(); #endif @@ -135,7 +137,7 @@ namespace Spine.Unity { animationTable.Add(a.Name.GetHashCode(), a); clipNameHashCodeTable.Clear(); - #if UNITY_2017_1_OR_NEWER + #if UNITY_CLIPINFOCACHE clipInfoCache.Clear(); nextClipInfoCache.Clear(); #endif @@ -263,7 +265,7 @@ namespace Spine.Unity { out int nextClipInfoCount, out IList clipInfo, out IList nextClipInfo) { - #if UNITY_2017_1_OR_NEWER + #if UNITY_CLIPINFOCACHE clipInfoCount = animator.GetCurrentAnimatorClipInfoCount(layer); nextClipInfoCount = animator.GetNextAnimatorClipInfoCount(layer); if (clipInfoCache.Capacity < clipInfoCount) clipInfoCache.Capacity = clipInfoCount; From 92cacd7e6de4d5315e0ae598ee93683a5556386a Mon Sep 17 00:00:00 2001 From: John Date: Mon, 8 Jan 2018 21:16:20 +0800 Subject: [PATCH 3/5] [unity] BoneFollower. Negate rotation from negative scaleX. --- spine-unity/Assets/spine-unity/BoneFollower.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index c7d3ea1a2..de68e8c1e 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -137,7 +137,16 @@ namespace Spine.Unity { if (skeletonTransformIsParent) { // Recommended setup: Use local transform properties if Spine GameObject is the immediate parent thisTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : thisTransform.localPosition.z); - if (followBoneRotation) thisTransform.localRotation = bone.GetQuaternion(); + if (followBoneRotation) { + var halfRotation = Mathf.Atan2(bone.c, bone.a) * 0.5f; + if (followLocalScale && bone.scaleX < 0) // Negate rotation from negative scaleX. Don't use negative determinant. local scaleY doesn't factor into used rotation. + halfRotation += Mathf.PI * 0.5f; + + var q = default(Quaternion); + q.z = Mathf.Sin(halfRotation); + q.w = Mathf.Cos(halfRotation); + thisTransform.localRotation = q; + } } else { // For special cases: Use transform world properties if transform relationship is complicated Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f)); From c2dea9f9fdfa5dd540b701084728a2a93920fdf7 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 9 Jan 2018 17:26:11 +0800 Subject: [PATCH 4/5] [unity] BoneFollower. Negate rotation from negative scaleX. --- spine-unity/Assets/spine-unity/BoneFollower.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index de68e8c1e..36e268c7c 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -163,6 +163,7 @@ namespace Spine.Unity { if (followBoneRotation) { Vector3 worldRotation = skeletonTransform.rotation.eulerAngles; + if (followLocalScale && bone.scaleX < 0) boneWorldRotation += 180f; #if UNITY_5_6_OR_NEWER thisTransform.SetPositionAndRotation(targetWorldPosition, Quaternion.Euler(worldRotation.x, worldRotation.y, skeletonTransform.rotation.eulerAngles.z + boneWorldRotation)); #else From 441658221692ce69e2a2591e570748c12a84eb56 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 9 Jan 2018 17:30:40 +0800 Subject: [PATCH 5/5] [unity] BoneFollower should use cached value. --- spine-unity/Assets/spine-unity/BoneFollower.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index 36e268c7c..b1b740281 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -165,10 +165,10 @@ namespace Spine.Unity { Vector3 worldRotation = skeletonTransform.rotation.eulerAngles; if (followLocalScale && bone.scaleX < 0) boneWorldRotation += 180f; #if UNITY_5_6_OR_NEWER - thisTransform.SetPositionAndRotation(targetWorldPosition, Quaternion.Euler(worldRotation.x, worldRotation.y, skeletonTransform.rotation.eulerAngles.z + boneWorldRotation)); + thisTransform.SetPositionAndRotation(targetWorldPosition, Quaternion.Euler(worldRotation.x, worldRotation.y, worldRotation.z + boneWorldRotation)); #else thisTransform.position = targetWorldPosition; - thisTransform.rotation = Quaternion.Euler(worldRotation.x, worldRotation.y, skeletonTransform.rotation.eulerAngles.z + bone.WorldRotationX); + thisTransform.rotation = Quaternion.Euler(worldRotation.x, worldRotation.y, worldRotation.z + bone.WorldRotationX); #endif } else { thisTransform.position = targetWorldPosition;