mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f9fd0f2570
@ -14,8 +14,6 @@ spine-cocos2dx works with data exported from Spine 3.5.xx.
|
|||||||
|
|
||||||
spine-cocos2dx supports all Spine features.
|
spine-cocos2dx supports all Spine features.
|
||||||
|
|
||||||
spine-cocos2dx does not yet support loading the binary format.
|
|
||||||
|
|
||||||
## Setup
|
## 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.
|
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.
|
||||||
|
|||||||
@ -85,6 +85,9 @@ namespace Spine.Unity {
|
|||||||
skeletonRenderer.OnRebuild -= HandleRebuildRenderer;
|
skeletonRenderer.OnRebuild -= HandleRebuildRenderer;
|
||||||
skeletonRenderer.OnRebuild += HandleRebuildRenderer;
|
skeletonRenderer.OnRebuild += HandleRebuildRenderer;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(boneName))
|
||||||
|
bone = skeletonRenderer.skeleton.FindBone(boneName);
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (Application.isEditor)
|
if (Application.isEditor)
|
||||||
LateUpdate();
|
LateUpdate();
|
||||||
|
|||||||
@ -37,17 +37,19 @@ namespace Spine.Unity.Editor {
|
|||||||
[CanEditMultipleObjects]
|
[CanEditMultipleObjects]
|
||||||
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty layerMixModes;
|
protected SerializedProperty layerMixModes;
|
||||||
|
protected SerializedProperty autoReset;
|
||||||
|
|
||||||
protected override void OnEnable () {
|
protected override void OnEnable () {
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
autoReset = serializedObject.FindProperty("autoReset");
|
||||||
layerMixModes = serializedObject.FindProperty("layerMixModes");
|
layerMixModes = serializedObject.FindProperty("layerMixModes");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DrawInspectorGUI (bool multi) {
|
protected override void DrawInspectorGUI (bool multi) {
|
||||||
base.DrawInspectorGUI(multi);
|
base.DrawInspectorGUI(multi);
|
||||||
|
EditorGUILayout.PropertyField(autoReset);
|
||||||
EditorGUILayout.PropertyField(layerMixModes, true);
|
EditorGUILayout.PropertyField(layerMixModes, true);
|
||||||
|
|
||||||
if (!TargetIsValid) return;
|
if (!TargetIsValid) return;
|
||||||
|
|
||||||
if (!isInspectingPrefab)
|
if (!isInspectingPrefab)
|
||||||
DrawSkeletonUtilityButton(multi);
|
DrawSkeletonUtilityButton(multi);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,9 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
public enum MixMode { AlwaysMix, MixNext, SpineStyle }
|
public enum MixMode { AlwaysMix, MixNext, SpineStyle }
|
||||||
public MixMode[] layerMixModes = new MixMode[0];
|
public MixMode[] layerMixModes = new MixMode[0];
|
||||||
|
|
||||||
public bool autoReset = false;
|
public bool autoReset = false;
|
||||||
|
List<Animation> previousAnimations = new List<Animation>();
|
||||||
|
|
||||||
#region Bone Callbacks (ISkeletonAnimation)
|
#region Bone Callbacks (ISkeletonAnimation)
|
||||||
protected event UpdateBonesDelegate _UpdateLocal;
|
protected event UpdateBonesDelegate _UpdateLocal;
|
||||||
@ -92,8 +94,14 @@ namespace Spine.Unity {
|
|||||||
// Clear Previous
|
// Clear Previous
|
||||||
if (autoReset)
|
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++) {
|
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;
|
if (layerWeight <= 0) continue;
|
||||||
|
|
||||||
AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layer);
|
AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layer);
|
||||||
@ -109,13 +117,15 @@ namespace Spine.Unity {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int c = 0; c < clipInfo.Length; c++) {
|
for (int c = 0; c < clipInfo.Length; c++) {
|
||||||
var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
|
var info = clipInfo[c];
|
||||||
animationTable[NameHashCode(info.clip)].SetKeyedItemsToSetupPose(skeleton);
|
float weight = info.weight * layerWeight; if (weight == 0) continue;
|
||||||
|
previousAnimations.Add(animationTable[NameHashCode(info.clip)]);
|
||||||
}
|
}
|
||||||
if (hasNext) {
|
if (hasNext) {
|
||||||
for (int c = 0; c < nextClipInfo.Length; c++) {
|
for (int c = 0; c < nextClipInfo.Length; c++) {
|
||||||
var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) continue;
|
var info = nextClipInfo[c];
|
||||||
animationTable[NameHashCode(info.clip)].SetKeyedItemsToSetupPose(skeleton);
|
float weight = info.weight * layerWeight; if (weight == 0) continue;
|
||||||
|
previousAnimations.Add(animationTable[NameHashCode(info.clip)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,10 +114,12 @@ namespace Spine.Unity {
|
|||||||
return new Vector2(bone.x, bone.y);
|
return new Vector2(bone.x, bone.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Gets the position of the bone in Skeleton-space.</summary>
|
||||||
public static Vector2 GetSkeletonSpacePosition (this Bone bone) {
|
public static Vector2 GetSkeletonSpacePosition (this Bone bone) {
|
||||||
return new Vector2(bone.worldX, bone.worldY);
|
return new Vector2(bone.worldX, bone.worldY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Gets a local offset from the bone and converts it into Skeleton-space.</summary>
|
||||||
public static Vector2 GetSkeletonSpacePosition (this Bone bone, Vector2 boneLocal) {
|
public static Vector2 GetSkeletonSpacePosition (this Bone bone, Vector2 boneLocal) {
|
||||||
Vector2 o;
|
Vector2 o;
|
||||||
bone.LocalToWorld(boneLocal.x, boneLocal.y, out o.x, out o.y);
|
bone.LocalToWorld(boneLocal.x, boneLocal.y, out o.x, out o.y);
|
||||||
@ -136,6 +138,7 @@ namespace Spine.Unity {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Outputs a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position.</summary>
|
||||||
public static void GetWorldToLocalMatrix (this Bone bone, out float ia, out float ib, out float ic, out float id) {
|
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 a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||||
float invDet = 1 / (a * d - b * c);
|
float invDet = 1 / (a * d - b * c);
|
||||||
@ -144,6 +147,13 @@ namespace Spine.Unity {
|
|||||||
ic = invDet * -c;
|
ic = invDet * -c;
|
||||||
id = invDet * a;
|
id = invDet * a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>UnityEngine.Vector2 override of Bone.WorldToLocal. This converts a skeleton-space position into a bone local position.</summary>
|
||||||
|
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
|
#endregion
|
||||||
|
|
||||||
#region Attachments
|
#region Attachments
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user