From f83c75e6593b6d57c8af96b50f926d616d663690 Mon Sep 17 00:00:00 2001 From: nicloay Date: Fri, 8 Aug 2014 14:42:34 +0400 Subject: [PATCH] bug, null attachments at slot animation --- .../Scripts/Editor/Util/SpineUtil.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs b/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs index 1f5a29b..a36a446 100644 --- a/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs +++ b/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs @@ -448,6 +448,15 @@ static void createFolderIfNoExists(string root, string folderName){ Directory.CreateDirectory(path); } + + public static string getFirstAttachmentName(SpineSlotAnimation spineSlotAnimation){ + for (int i = 0; i < spineSlotAnimation.attachment.Count; i++) { + if (!string.IsNullOrEmpty( spineSlotAnimation.attachment[i].name)) + return spineSlotAnimation.attachment[i].name; + } + return ""; + } + public static void addSlotAnimationToClip(AnimationClip clip, Dictionary slotsAnimation, SpineData spineData, @@ -461,11 +470,18 @@ public static void addSlotAnimationToClip(AnimationClip SpineSlotAnimation slotAnimation = kvp.Value; if (slotAnimation.attachment != null && slotAnimation.attachment.Count > 0){ Dictionary curveByName = new Dictionary(); + + for (int i = 0; i < slotAnimation.attachment.Count; i++) { + bool nullAttachment = false; SpineSlotAttachmentAnimation anim = slotAnimation.attachment[i]; - if (string.IsNullOrEmpty( anim.name)) - continue; + if (string.IsNullOrEmpty( anim.name)){ + anim.name=getFirstAttachmentName(slotAnimation); + nullAttachment = true; + } + if (anim.name.Equals("")) + continue; AnimationCurve enableCurve; if (curveByName.ContainsKey(anim.name)){ enableCurve = curveByName[anim.name]; @@ -481,7 +497,7 @@ public static void addSlotAnimationToClip(AnimationClip curveByName.Add(defaultAttachment, defSlotCurve); if (anim.time !=0.0f){ - defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 1, TangentMode.Stepped)); + defSlotCurve.AddKey(KeyframeUtil.GetNew(0, nullAttachment ? 0 : 1, TangentMode.Stepped)); defSlotCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 0, TangentMode.Stepped)); } else { defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 0, TangentMode.Stepped)); @@ -490,11 +506,18 @@ public static void addSlotAnimationToClip(AnimationClip } } - enableCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 1, TangentMode.Stepped)); + enableCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, nullAttachment ? 0 : 1, TangentMode.Stepped)); if (i< (slotAnimation.attachment.Count - 1)){ SpineSlotAttachmentAnimation nextAnim = slotAnimation.attachment[i+1]; - if (!nextAnim.name.Equals(anim.name)) + bool nullNextAttachment =false; + if (string.IsNullOrEmpty( nextAnim.name)){ + nextAnim.name=getFirstAttachmentName(slotAnimation); + nullNextAttachment = true; + } + + if (!nextAnim.name.Equals(anim.name) || nullNextAttachment) enableCurve.AddKey(KeyframeUtil.GetNew((float)nextAnim.time, 0, TangentMode.Stepped)); + } } foreach(KeyValuePair kvp2 in curveByName){