From 0279c3a391a5fde989090af4d0aeff1dedde338c Mon Sep 17 00:00:00 2001 From: pharan Date: Mon, 26 Dec 2016 11:30:05 +0800 Subject: [PATCH 1/5] [unity] SkeletonAnimator deferred autoReset. --- .../Editor/SkeletonAnimatorInspector.cs | 6 ++++-- .../Assets/spine-unity/SkeletonAnimator.cs | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs index 8204cd800..42a618c6f 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs @@ -37,17 +37,19 @@ namespace Spine.Unity.Editor { [CanEditMultipleObjects] public class SkeletonAnimatorInspector : SkeletonRendererInspector { protected SerializedProperty layerMixModes; + protected SerializedProperty autoReset; + protected override void OnEnable () { base.OnEnable(); + autoReset = serializedObject.FindProperty("autoReset"); layerMixModes = serializedObject.FindProperty("layerMixModes"); } protected override void DrawInspectorGUI (bool multi) { base.DrawInspectorGUI(multi); + EditorGUILayout.PropertyField(autoReset); EditorGUILayout.PropertyField(layerMixModes, true); - if (!TargetIsValid) return; - if (!isInspectingPrefab) DrawSkeletonUtilityButton(multi); } diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index 76cfbc3f1..dce8bc22e 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -39,7 +39,9 @@ namespace Spine.Unity { public enum MixMode { AlwaysMix, MixNext, SpineStyle } public MixMode[] layerMixModes = new MixMode[0]; + public bool autoReset = false; + List previousAnimations = new List(); #region Bone Callbacks (ISkeletonAnimation) protected event UpdateBonesDelegate _UpdateLocal; @@ -92,6 +94,12 @@ namespace Spine.Unity { // Clear Previous if (autoReset) { + var previousAnimations = this.previousAnimations; + for (int i = 0, n = previousAnimations.Count; i < n; i++) { + previousAnimations[i].SetKeyedItemsToSetupPose(skeleton); + } + previousAnimations.Clear(); + for (int layer = 0, n = animator.layerCount; layer < n; layer++) { float layerWeight = animator.GetLayerWeight(layer); if (layerWeight <= 0) continue; @@ -109,13 +117,15 @@ namespace Spine.Unity { #endif for (int c = 0; c < clipInfo.Length; c++) { - var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].SetKeyedItemsToSetupPose(skeleton); + var info = clipInfo[c]; + float weight = info.weight * layerWeight; if (weight == 0) continue; + previousAnimations.Add(animationTable[NameHashCode(info.clip)]); } if (hasNext) { for (int c = 0; c < nextClipInfo.Length; c++) { - var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue; - animationTable[NameHashCode(info.clip)].SetKeyedItemsToSetupPose(skeleton); + var info = nextClipInfo[c]; + float weight = info.weight * layerWeight; if (weight == 0) continue; + previousAnimations.Add(animationTable[NameHashCode(info.clip)]); } } } From 68fb6e78aeb4abcc1b1e97cbf11eed3d6b8cf2f5 Mon Sep 17 00:00:00 2001 From: pharan Date: Mon, 26 Dec 2016 11:31:13 +0800 Subject: [PATCH 2/5] [unity] BoneFollower find bone on initialization. --- spine-unity/Assets/spine-unity/BoneFollower.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index b676f5b40..71027b97c 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -85,6 +85,9 @@ namespace Spine.Unity { skeletonRenderer.OnRebuild -= HandleRebuildRenderer; skeletonRenderer.OnRebuild += HandleRebuildRenderer; + if (!string.IsNullOrEmpty(boneName)) + bone = skeletonRenderer.skeleton.FindBone(boneName); + #if UNITY_EDITOR if (Application.isEditor) LateUpdate(); From 73f8779efc9e02af152c48290eefcc5b714f2512 Mon Sep 17 00:00:00 2001 From: pharan Date: Mon, 26 Dec 2016 11:32:19 +0800 Subject: [PATCH 3/5] [unity] Minor extensions update. --- spine-unity/Assets/spine-unity/SkeletonExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs index 7773bf8ea..8f04b0a8b 100644 --- a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs @@ -114,10 +114,12 @@ namespace Spine.Unity { return new Vector2(bone.x, bone.y); } + /// Gets the position of the bone in Skeleton-space. public static Vector2 GetSkeletonSpacePosition (this Bone bone) { return new Vector2(bone.worldX, bone.worldY); } + /// Gets a local offset from the bone and converts it into Skeleton-space. public static Vector2 GetSkeletonSpacePosition (this Bone bone, Vector2 boneLocal) { Vector2 o; bone.LocalToWorld(boneLocal.x, boneLocal.y, out o.x, out o.y); @@ -136,6 +138,7 @@ namespace Spine.Unity { }; } + /// Outputs a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position. public static void GetWorldToLocalMatrix (this Bone bone, out float ia, out float ib, out float ic, out float id) { float a = bone.a, b = bone.b, c = bone.c, d = bone.d; float invDet = 1 / (a * d - b * c); @@ -144,6 +147,13 @@ namespace Spine.Unity { ic = invDet * -c; id = invDet * a; } + + /// UnityEngine.Vector2 override of Bone.WorldToLocal. This converts a skeleton-space position into a bone local position. + public static Vector2 WorldToLocal (this Bone bone, Vector2 worldPosition) { + Vector2 o; + bone.WorldToLocal(worldPosition.x, worldPosition.y, out o.x, out o.y); + return o; + } #endregion #region Attachments From c1dce1f476fe314ddefd706070ec7d612804a0e7 Mon Sep 17 00:00:00 2001 From: pharan Date: Tue, 27 Dec 2016 14:21:10 +0800 Subject: [PATCH 4/5] [unity] Fix SkeletonAnimator autoreset weight. --- spine-unity/Assets/spine-unity/SkeletonAnimator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index dce8bc22e..e94829428 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -101,7 +101,7 @@ namespace Spine.Unity { previousAnimations.Clear(); for (int layer = 0, n = animator.layerCount; layer < n; layer++) { - float layerWeight = animator.GetLayerWeight(layer); + float layerWeight = (layer == 0) ? 1 : animator.GetLayerWeight(layer); if (layerWeight <= 0) continue; AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layer); From 4dacc8c67c6ca1b3aeca5ab5b0f9aa65ff12ac68 Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 27 Dec 2016 11:06:59 +0100 Subject: [PATCH 5/5] [cocos2dx] Updated README --- spine-cocos2dx/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/spine-cocos2dx/README.md b/spine-cocos2dx/README.md index 229cc3989..0690693a2 100644 --- a/spine-cocos2dx/README.md +++ b/spine-cocos2dx/README.md @@ -14,8 +14,6 @@ spine-cocos2dx works with data exported from Spine 3.5.xx. spine-cocos2dx supports all Spine features. -spine-cocos2dx does not yet support loading the binary format. - ## Setup The setup for cocos2d-x differs from most other Spine Runtimes because the cocos2d-x distribution includes a copy of the Spine Runtime files. This is not ideal because these files may be old and fail to work with the latest Spine editor. Also it means if cocos2d-x is updated, you may get newer Spine Runtime files which can break your application if you are not using the latest Spine editor. For these reasons, we have requested cocos2d-x to cease distributing the Spine Runtime files, but they continue to do so. The following instructions allow you to use the official Spine cocos2d-x runtime with your cocos2d-x project.