@@ -21,9 +21,10 @@ public AtlasImageDuplicateSpriteName(string message):base(message){
21
21
}
22
22
23
23
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 = "|" ;
27
28
28
29
public static Vector2 lineToVector2 ( string line ) {
29
30
string [ ] xy = null ;
@@ -297,17 +298,18 @@ public static void addAllAttahcmentsSlots(SpineData spineData, SpritesByName spr
297
298
298
299
GameObject parentGO ;
299
300
GameObject spriteGO ;
301
+ string fixedName = attachmenName . Replace ( "/" , SLASH_REPLACEMENT ) ;
300
302
if ( isDefault ) {
301
303
parentGO = slotGO ;
302
- spriteGO = new GameObject ( attachmenName ) ;
304
+ spriteGO = new GameObject ( fixedName ) ;
303
305
Attachment a = new Attachment ( attachmenName , AttachmentType . SINGLE_SPRITE , spriteGO ) ;
304
306
slot . addAttachment ( a ) ;
305
307
} else {
306
308
spriteGO = new GameObject ( skinName ) ;
307
309
Attachment a ;
308
310
slot . attachmentByName . TryGetValue ( attachmenName , out a ) ;
309
311
if ( a == null ) {
310
- GameObject attachmentGO = new GameObject ( attachmenName ) ;
312
+ GameObject attachmentGO = new GameObject ( fixedName ) ;
311
313
attachmentGO . transform . parent = slotGO . transform ;
312
314
resetLocalTRS ( attachmentGO ) ;
313
315
a = new Attachment ( attachmenName , AttachmentType . SKINED_SPRITE , attachmentGO ) ;
@@ -433,6 +435,7 @@ public static void addSlotAnimationToClip(AnimationClip
433
435
{
434
436
foreach ( KeyValuePair < string , SpineSlotAnimation > kvp in slotsAnimation ) {
435
437
string slotName = kvp . Key ;
438
+ string defaultAttachment = spineData . slotDefaultAttachments [ slotName ] ;
436
439
SpineSlotAnimation slotAnimation = kvp . Value ;
437
440
if ( slotAnimation . attachment != null && slotAnimation . attachment . Count > 0 ) {
438
441
Dictionary < string , AnimationCurve > curveByName = new Dictionary < string , AnimationCurve > ( ) ;
@@ -446,22 +449,37 @@ public static void addSlotAnimationToClip(AnimationClip
446
449
enableCurve = curveByName [ anim . name ] ;
447
450
} else {
448
451
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
+
452
455
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
+ }
453
469
}
454
470
455
471
enableCurve . AddKey ( KeyframeUtil . GetNew ( ( float ) anim . time , 1 , TangentMode . Stepped ) ) ;
456
472
if ( i < ( slotAnimation . attachment . Count - 1 ) ) {
457
473
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 ) ) ;
459
476
}
460
477
}
461
478
foreach ( KeyValuePair < string , AnimationCurve > kvp2 in curveByName ) {
462
479
string attachmentName = kvp2 . Key ;
463
480
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 ) ;
465
483
clip . SetCurve ( attachmentPath , typeof ( GameObject ) , "m_IsActive" , animationCurve ) ;
466
484
}
467
485
0 commit comments