Skip to content

Commit 7ff1e1c

Browse files
committed
Merge branch 'release/v0.2.2'
2 parents 9133da5 + d6e175e commit 7ff1e1c

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

Assets/UnitySpineImporter/Scripts/Editor/Model/Spine/Data/SpineData.cs

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class SpineData{
2929
public string defaultSkinName;
3030
public string[] skinNames;
3131
public string[] defaultPoseSlots;
32+
public Dictionary<string,string> slotDefaultAttachments;
3233

3334

3435

@@ -95,13 +96,16 @@ static void setCachedData (SpineData data)
9596
data.slotOrder = new Dictionary<string, int>();
9697

9798
data.slotPathByName = new Dictionary<string, string>();
99+
data.slotDefaultAttachments = new Dictionary<string, string>();
98100
for (int i = 0; i < data.slots.Count; i++) {
99101
string slotName = data.slots[i].name;
102+
string defaultAttachment = data.slots[i].attachment;
100103
data.slotOrder.Add(slotName, i);
101104
string boneName = data.slots[i].bone;
102105
string bonePath = data.bonePathByName[boneName];
103106
string slotPath = bonePath+"/" + SpineUtil.getSlotGOName(slotName);
104107
data.slotPathByName.Add(slotName, slotPath);
108+
data.slotDefaultAttachments.Add(slotName, defaultAttachment);
105109
}
106110
}
107111

Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs

+28-10
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public AtlasImageDuplicateSpriteName(string message):base(message){
2121
}
2222

2323
public class SpineUtil {
24-
public static string SLOT_PREFIX="slot";
25-
public static string SKIN_PREFIX="skin";
26-
public static string ANIMATION_FOLDER="animation";
24+
public static string SLOT_PREFIX = "slot";
25+
public static string SKIN_PREFIX = "skin";
26+
public static string ANIMATION_FOLDER = "animation";
27+
public static string SLASH_REPLACEMENT = "|";
2728

2829
public static Vector2 lineToVector2(string line){
2930
string[] xy = null;
@@ -297,17 +298,18 @@ public static void addAllAttahcmentsSlots(SpineData spineData, SpritesByName spr
297298

298299
GameObject parentGO;
299300
GameObject spriteGO;
301+
string fixedName = attachmenName.Replace("/",SLASH_REPLACEMENT);
300302
if (isDefault){
301303
parentGO = slotGO;
302-
spriteGO = new GameObject(attachmenName);
304+
spriteGO = new GameObject(fixedName);
303305
Attachment a = new Attachment(attachmenName, AttachmentType.SINGLE_SPRITE, spriteGO);
304306
slot.addAttachment(a);
305307
} else {
306308
spriteGO = new GameObject(skinName);
307309
Attachment a;
308310
slot.attachmentByName.TryGetValue(attachmenName, out a);
309311
if (a == null){
310-
GameObject attachmentGO = new GameObject(attachmenName);
312+
GameObject attachmentGO = new GameObject(fixedName);
311313
attachmentGO.transform.parent = slotGO.transform;
312314
resetLocalTRS(attachmentGO);
313315
a = new Attachment(attachmenName, AttachmentType.SKINED_SPRITE, attachmentGO);
@@ -433,6 +435,7 @@ public static void addSlotAnimationToClip(AnimationClip
433435
{
434436
foreach(KeyValuePair<string, SpineSlotAnimation> kvp in slotsAnimation){
435437
string slotName = kvp.Key;
438+
string defaultAttachment = spineData.slotDefaultAttachments[slotName];
436439
SpineSlotAnimation slotAnimation = kvp.Value;
437440
if (slotAnimation.attachment != null && slotAnimation.attachment.Count > 0){
438441
Dictionary<string, AnimationCurve> curveByName = new Dictionary<string, AnimationCurve>();
@@ -446,22 +449,37 @@ public static void addSlotAnimationToClip(AnimationClip
446449
enableCurve = curveByName[anim.name];
447450
} else {
448451
enableCurve = new AnimationCurve();
449-
if ((i==0 && anim.time != 0) || i > 0){
450-
enableCurve.AddKey(KeyframeUtil.GetNew(0, 0, TangentMode.Stepped));
451-
}
452+
if (anim.time > 0.0f)
453+
enableCurve.AddKey(KeyframeUtil.GetNew(0, 0.0f, TangentMode.Stepped));
454+
452455
curveByName.Add(anim.name, enableCurve);
456+
457+
if (i==0 && !anim.name.Equals(defaultAttachment)){
458+
AnimationCurve defSlotCurve = new AnimationCurve();
459+
curveByName.Add(defaultAttachment, defSlotCurve);
460+
461+
if (anim.time !=0.0f){
462+
defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 1, TangentMode.Stepped));
463+
defSlotCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 0, TangentMode.Stepped));
464+
} else {
465+
defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 0, TangentMode.Stepped));
466+
}
467+
468+
}
453469
}
454470

455471
enableCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 1, TangentMode.Stepped));
456472
if (i< (slotAnimation.attachment.Count - 1)){
457473
SpineSlotAttachmentAnimation nextAnim = slotAnimation.attachment[i+1];
458-
enableCurve.AddKey(KeyframeUtil.GetNew((float)nextAnim.time, 0, TangentMode.Stepped));
474+
if (!nextAnim.name.Equals(anim.name))
475+
enableCurve.AddKey(KeyframeUtil.GetNew((float)nextAnim.time, 0, TangentMode.Stepped));
459476
}
460477
}
461478
foreach(KeyValuePair<string, AnimationCurve> kvp2 in curveByName){
462479
string attachmentName = kvp2.Key;
463480
AnimationCurve animationCurve = kvp2.Value;
464-
string attachmentPath = spineData.slotPathByName[slotName] + "/" + attachmentName;
481+
string attachmentPath = spineData.slotPathByName[slotName] + "/" + attachmentName.Replace("/",SLASH_REPLACEMENT);
482+
Debug.Log(attachmentPath);
465483
clip.SetCurve(attachmentPath, typeof(GameObject),"m_IsActive", animationCurve);
466484
}
467485

0 commit comments

Comments
 (0)