@@ -448,6 +448,15 @@ static void createFolderIfNoExists(string root, string folderName){
448
448
Directory . CreateDirectory ( path ) ;
449
449
}
450
450
451
+
452
+ public static string getFirstAttachmentName ( SpineSlotAnimation spineSlotAnimation ) {
453
+ for ( int i = 0 ; i < spineSlotAnimation . attachment . Count ; i ++ ) {
454
+ if ( ! string . IsNullOrEmpty ( spineSlotAnimation . attachment [ i ] . name ) )
455
+ return spineSlotAnimation . attachment [ i ] . name ;
456
+ }
457
+ return "" ;
458
+ }
459
+
451
460
public static void addSlotAnimationToClip ( AnimationClip clip ,
452
461
Dictionary < string , SpineSlotAnimation > slotsAnimation ,
453
462
SpineData spineData ,
@@ -461,11 +470,18 @@ public static void addSlotAnimationToClip(AnimationClip
461
470
SpineSlotAnimation slotAnimation = kvp . Value ;
462
471
if ( slotAnimation . attachment != null && slotAnimation . attachment . Count > 0 ) {
463
472
Dictionary < string , AnimationCurve > curveByName = new Dictionary < string , AnimationCurve > ( ) ;
473
+
474
+
464
475
for ( int i = 0 ; i < slotAnimation . attachment . Count ; i ++ ) {
476
+ bool nullAttachment = false ;
465
477
SpineSlotAttachmentAnimation anim = slotAnimation . attachment [ i ] ;
466
- if ( string . IsNullOrEmpty ( anim . name ) )
467
- continue ;
478
+ if ( string . IsNullOrEmpty ( anim . name ) ) {
479
+ anim . name = getFirstAttachmentName ( slotAnimation ) ;
480
+ nullAttachment = true ;
481
+ }
468
482
483
+ if ( anim . name . Equals ( "" ) )
484
+ continue ;
469
485
AnimationCurve enableCurve ;
470
486
if ( curveByName . ContainsKey ( anim . name ) ) {
471
487
enableCurve = curveByName [ anim . name ] ;
@@ -481,7 +497,7 @@ public static void addSlotAnimationToClip(AnimationClip
481
497
curveByName . Add ( defaultAttachment , defSlotCurve ) ;
482
498
483
499
if ( anim . time != 0.0f ) {
484
- defSlotCurve . AddKey ( KeyframeUtil . GetNew ( 0 , 1 , TangentMode . Stepped ) ) ;
500
+ defSlotCurve . AddKey ( KeyframeUtil . GetNew ( 0 , nullAttachment ? 0 : 1 , TangentMode . Stepped ) ) ;
485
501
defSlotCurve . AddKey ( KeyframeUtil . GetNew ( ( float ) anim . time , 0 , TangentMode . Stepped ) ) ;
486
502
} else {
487
503
defSlotCurve . AddKey ( KeyframeUtil . GetNew ( 0 , 0 , TangentMode . Stepped ) ) ;
@@ -490,11 +506,18 @@ public static void addSlotAnimationToClip(AnimationClip
490
506
}
491
507
}
492
508
493
- enableCurve . AddKey ( KeyframeUtil . GetNew ( ( float ) anim . time , 1 , TangentMode . Stepped ) ) ;
509
+ enableCurve . AddKey ( KeyframeUtil . GetNew ( ( float ) anim . time , nullAttachment ? 0 : 1 , TangentMode . Stepped ) ) ;
494
510
if ( i < ( slotAnimation . attachment . Count - 1 ) ) {
495
511
SpineSlotAttachmentAnimation nextAnim = slotAnimation . attachment [ i + 1 ] ;
496
- if ( ! nextAnim . name . Equals ( anim . name ) )
512
+ bool nullNextAttachment = false ;
513
+ if ( string . IsNullOrEmpty ( nextAnim . name ) ) {
514
+ nextAnim . name = getFirstAttachmentName ( slotAnimation ) ;
515
+ nullNextAttachment = true ;
516
+ }
517
+
518
+ if ( ! nextAnim . name . Equals ( anim . name ) || nullNextAttachment )
497
519
enableCurve . AddKey ( KeyframeUtil . GetNew ( ( float ) nextAnim . time , 0 , TangentMode . Stepped ) ) ;
520
+
498
521
}
499
522
}
500
523
foreach ( KeyValuePair < string , AnimationCurve > kvp2 in curveByName ) {
0 commit comments