Skip to content

Commit

Permalink
Merge branch '3.6' into 3.7-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Jan 9, 2018
2 parents d4d9f71 + 4416582 commit cbc8231
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 13 additions & 3 deletions spine-unity/Assets/spine-unity/BoneFollower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ public void LateUpdate () {
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));
Expand All @@ -154,11 +163,12 @@ public void LateUpdate () {

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));
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;
Expand Down
20 changes: 15 additions & 5 deletions spine-unity/Assets/spine-unity/SkeletonAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,21 +118,29 @@ public enum MixMode { AlwaysMix, MixNext, SpineStyle }
readonly Dictionary<int, Spine.Animation> animationTable = new Dictionary<int, Spine.Animation>(IntEqualityComparer.Instance);
readonly Dictionary<AnimationClip, int> clipNameHashCodeTable = new Dictionary<AnimationClip, int>(AnimationClipEqualityComparer.Instance);
readonly List<Animation> previousAnimations = new List<Animation>();
#if UNITY_2017_1_OR_NEWER
#if UNITY_CLIPINFOCACHE
readonly List<AnimatorClipInfo> clipInfoCache = new List<AnimatorClipInfo>();
readonly List<AnimatorClipInfo> nextClipInfoCache = new List<AnimatorClipInfo>();
#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_CLIPINFOCACHE
clipInfoCache.Clear();
nextClipInfoCache.Clear();
#endif
}

public void Apply (Skeleton skeleton) {
Expand Down Expand Up @@ -255,7 +265,7 @@ void GetAnimatorClipInfos (
out int nextClipInfoCount,
out IList<AnimatorClipInfo> clipInfo,
out IList<AnimatorClipInfo> 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;
Expand Down

0 comments on commit cbc8231

Please sign in to comment.