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. 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(); 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..e94829428 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,8 +94,14 @@ 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); + float layerWeight = (layer == 0) ? 1 : animator.GetLayerWeight(layer); if (layerWeight <= 0) continue; AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layer); @@ -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)]); } } } 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