Merge remote-tracking branch 'origin/master'

This commit is contained in:
NathanSweet 2016-12-28 19:51:37 +01:00
commit f9fd0f2570
5 changed files with 32 additions and 9 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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);
}

View File

@ -39,7 +39,9 @@ namespace Spine.Unity {
public enum MixMode { AlwaysMix, MixNext, SpineStyle }
public MixMode[] layerMixModes = new MixMode[0];
public bool autoReset = false;
List<Animation> previousAnimations = new List<Animation>();
#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)]);
}
}
}

View File

@ -114,10 +114,12 @@ namespace Spine.Unity {
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) {
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) {
Vector2 o;
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) {
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;
}
/// <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
#region Attachments