@@ -2213,6 +2213,14 @@ protected int ExportAnimationOnly(
2213
2213
}
2214
2214
2215
2215
// export animation
2216
+
2217
+ // export default clip first
2218
+ if ( exportData . defaultClip != null ) {
2219
+ var defaultClip = exportData . defaultClip ;
2220
+ ExportAnimationClip ( defaultClip , exportData . animationClips [ defaultClip ] , fbxScene ) ;
2221
+ exportData . animationClips . Remove ( defaultClip ) ;
2222
+ }
2223
+
2216
2224
foreach ( var animClip in exportData . animationClips ) {
2217
2225
ExportAnimationClip ( animClip . Key , animClip . Value , fbxScene ) ;
2218
2226
}
@@ -2402,19 +2410,68 @@ out Dictionary<GameObject, AnimationOnlyExportData> hierarchyToExportData
2402
2410
2403
2411
hierarchyToExportData . Add ( go , exportData ) ;
2404
2412
2413
+ int fromRoot = int . MaxValue ;
2414
+ Animation rootAnimation = null ;
2405
2415
foreach ( var anim in legacyAnim ) {
2416
+ int count = 0 ;
2417
+ var parent = anim . transform . parent ;
2418
+ while ( parent != null && parent != go . transform ) {
2419
+ count ++ ;
2420
+ parent = parent . parent ;
2421
+ }
2422
+
2423
+ if ( count < fromRoot ) {
2424
+ fromRoot = count ;
2425
+ rootAnimation = anim ;
2426
+ }
2427
+
2406
2428
var animClips = AnimationUtility . GetAnimationClips ( anim . gameObject ) ;
2407
2429
GetObjectsInAnimationClips ( animClips , anim . gameObject , ref exportData ) ;
2408
2430
}
2409
2431
2432
+ int aFromRoot = int . MaxValue ;
2433
+ Animator rootAnimator = null ;
2410
2434
foreach ( var anim in genericAnim ) {
2435
+ int count = 0 ;
2436
+ var parent = anim . transform . parent ;
2437
+ while ( parent != null && parent != go . transform ) {
2438
+ count ++ ;
2439
+ parent = parent . parent ;
2440
+ }
2441
+
2442
+ if ( count < aFromRoot ) {
2443
+ aFromRoot = count ;
2444
+ rootAnimator = anim ;
2445
+ }
2446
+
2411
2447
// Try the animator controller (mecanim)
2412
2448
var controller = anim . runtimeAnimatorController ;
2413
2449
if ( controller )
2414
2450
{
2415
2451
GetObjectsInAnimationClips ( controller . animationClips , anim . gameObject , ref exportData ) ;
2416
2452
}
2417
2453
}
2454
+
2455
+ // set the first clip to export
2456
+ if ( fromRoot < aFromRoot ) {
2457
+ exportData . defaultClip = rootAnimation . clip ;
2458
+ } else {
2459
+ // Try the animator controller (mecanim)
2460
+ var controller = rootAnimator . runtimeAnimatorController ;
2461
+ if ( controller ) {
2462
+ var dController = controller as UnityEditor . Animations . AnimatorController ;
2463
+ if ( dController && dController . layers . Count ( ) > 0 ) {
2464
+ var motion = dController . layers [ 0 ] . stateMachine . defaultState . motion ;
2465
+ var defaultClip = motion as AnimationClip ;
2466
+ if ( defaultClip ) {
2467
+ Debug . LogWarning ( "default clip: " + defaultClip . name ) ;
2468
+ exportData . defaultClip = defaultClip ;
2469
+ } else {
2470
+ Debug . LogWarningFormat ( "Couldn't export motion {0}" , motion . name ) ;
2471
+ }
2472
+ }
2473
+ }
2474
+ }
2418
2475
}
2419
2476
2420
2477
// including any parents of animated objects that are exported
0 commit comments