@@ -2176,15 +2176,29 @@ protected int ExportTransformHierarchy(
2176
2176
return numObjectsExported ;
2177
2177
}
2178
2178
2179
- protected void ExportAnimationOnly (
2179
+ public struct AnimationOnlyExportData {
2180
+ public Dictionary < AnimationClip , GameObject > animationClips ;
2181
+ public HashSet < GameObject > goExportSet ;
2182
+ public Dictionary < GameObject , System . Type > exportComponent ;
2183
+
2184
+ public AnimationOnlyExportData (
2185
+ Dictionary < AnimationClip , GameObject > animClips ,
2186
+ HashSet < GameObject > exportSet ,
2187
+ Dictionary < GameObject , System . Type > exportComponent
2188
+ ) {
2189
+ this . animationClips = animClips ;
2190
+ this . goExportSet = exportSet ;
2191
+ this . exportComponent = exportComponent ;
2192
+ }
2193
+ }
2194
+
2195
+ protected int ExportAnimationOnly (
2180
2196
GameObject unityGO ,
2181
2197
FbxScene fbxScene ,
2182
2198
int exportProgress ,
2183
2199
int objectCount ,
2184
2200
Vector3 newCenter ,
2185
- Dictionary < AnimationClip , GameObject > animationClips ,
2186
- HashSet < GameObject > goExportSet ,
2187
- Dictionary < GameObject , System . Type > exportComponent ,
2201
+ AnimationOnlyExportData exportData ,
2188
2202
TransformExportType exportType = TransformExportType . Local
2189
2203
) {
2190
2204
// export any bones
@@ -2203,10 +2217,10 @@ protected void ExportAnimationOnly(
2203
2217
var rootBone = skinnedMesh . rootBone ;
2204
2218
2205
2219
// get the bones that are also in the export set
2206
- bones . IntersectWith ( goExportSet ) ;
2220
+ bones . IntersectWith ( exportData . goExportSet ) ;
2207
2221
2208
2222
// remove the exported bones from the export set
2209
- goExportSet . ExceptWith ( bones ) ;
2223
+ exportData . goExportSet . ExceptWith ( bones ) ;
2210
2224
2211
2225
foreach ( var bone in bones ) {
2212
2226
FbxNode node ;
@@ -2217,14 +2231,14 @@ protected void ExportAnimationOnly(
2217
2231
}
2218
2232
2219
2233
// export everything else
2220
- foreach ( var go in goExportSet ) {
2234
+ foreach ( var go in exportData . goExportSet ) {
2221
2235
FbxNode node ;
2222
2236
ExportGameObjectAndParents (
2223
2237
go , unityGO , fbxScene , out node , newCenter , exportType , exportProgress , objectCount
2224
2238
) ;
2225
2239
2226
2240
System . Type compType ;
2227
- if ( exportComponent . TryGetValue ( go , out compType ) ) {
2241
+ if ( exportData . exportComponent . TryGetValue ( go , out compType ) ) {
2228
2242
if ( compType == typeof ( Light ) ) {
2229
2243
ExportLight ( go , fbxScene , node ) ;
2230
2244
} else if ( compType == typeof ( Camera ) ) {
@@ -2234,9 +2248,11 @@ protected void ExportAnimationOnly(
2234
2248
}
2235
2249
2236
2250
// export animation
2237
- foreach ( var animClip in animationClips ) {
2251
+ foreach ( var animClip in exportData . animationClips ) {
2238
2252
ExportAnimationClip ( animClip . Key , animClip . Value , fbxScene ) ;
2239
2253
}
2254
+
2255
+ return 0 ;
2240
2256
}
2241
2257
2242
2258
private bool ExportGameObjectAndParents (
@@ -2392,42 +2408,43 @@ private bool ExportBoneTransform(
2392
2408
return true ;
2393
2409
}
2394
2410
2395
- protected int AnimOnlyHierarchyCount (
2411
+ protected int GetAnimOnlyHierarchyCount (
2396
2412
HashSet < GameObject > exportSet ,
2397
- out Dictionary < AnimationClip , GameObject > animationClips ,
2398
- out Dictionary < GameObject , HashSet < GameObject > > mapGameObjectToExportSet ,
2399
- out Dictionary < GameObject , System . Type > exportComponent
2413
+ out Dictionary < GameObject , AnimationOnlyExportData > hierarchyToExportData
2400
2414
) {
2401
- animationClips = new Dictionary < AnimationClip , GameObject > ( ) ;
2402
- mapGameObjectToExportSet = new Dictionary < GameObject , HashSet < GameObject > > ( ) ;
2403
- exportComponent = new Dictionary < GameObject , System . Type > ( ) ;
2415
+ hierarchyToExportData = new Dictionary < GameObject , AnimationOnlyExportData > ( ) ;
2404
2416
2405
2417
foreach ( var go in exportSet ) {
2406
2418
// gather all animation clips
2407
2419
var legacyAnim = go . GetComponentsInChildren < Animation > ( ) ;
2408
2420
var genericAnim = go . GetComponentsInChildren < Animator > ( ) ;
2409
2421
2410
2422
var goToExport = new HashSet < GameObject > ( ) ;
2411
- mapGameObjectToExportSet . Add ( go , goToExport ) ;
2423
+ var animationClips = new Dictionary < AnimationClip , GameObject > ( ) ;
2424
+ var exportComponent = new Dictionary < GameObject , System . Type > ( ) ;
2425
+
2426
+ var exportData = new AnimationOnlyExportData ( animationClips , goToExport , exportComponent ) ;
2427
+
2428
+ hierarchyToExportData . Add ( go , exportData ) ;
2412
2429
2413
2430
foreach ( var anim in legacyAnim ) {
2414
2431
var animClips = AnimationUtility . GetAnimationClips ( anim . gameObject ) ;
2415
- GetObjectsInAnimationClips ( animClips , anim . gameObject , ref animationClips , ref goToExport , ref exportComponent ) ;
2432
+ GetObjectsInAnimationClips ( animClips , anim . gameObject , ref exportData ) ;
2416
2433
}
2417
2434
2418
2435
foreach ( var anim in genericAnim ) {
2419
2436
// Try the animator controller (mecanim)
2420
2437
var controller = anim . runtimeAnimatorController ;
2421
2438
if ( controller )
2422
2439
{
2423
- GetObjectsInAnimationClips ( controller . animationClips , anim . gameObject , ref animationClips , ref goToExport , ref exportComponent ) ;
2440
+ GetObjectsInAnimationClips ( controller . animationClips , anim . gameObject , ref exportData ) ;
2424
2441
}
2425
2442
}
2426
2443
}
2427
2444
2428
2445
int count = 0 ;
2429
- foreach ( var es in mapGameObjectToExportSet . Values ) {
2430
- count += es . Count ;
2446
+ foreach ( var data in hierarchyToExportData . Values ) {
2447
+ count += data . goExportSet . Count ;
2431
2448
}
2432
2449
2433
2450
return count ;
@@ -2436,20 +2453,18 @@ protected int AnimOnlyHierarchyCount(
2436
2453
protected void GetObjectsInAnimationClips (
2437
2454
AnimationClip [ ] animClips ,
2438
2455
GameObject animationRootObject ,
2439
- ref Dictionary < AnimationClip , GameObject > clipSet ,
2440
- ref HashSet < GameObject > goToExport ,
2441
- ref Dictionary < GameObject , System . Type > exportComponent
2456
+ ref AnimationOnlyExportData exportData
2442
2457
) {
2443
2458
var cameraProps = new List < string > { "field of view" } ;
2444
2459
var lightProps = new List < string > { "m_Intensity" , "m_SpotAngle" , "m_Color.r" , "m_Color.g" , "m_Color.b" } ;
2445
2460
2446
2461
foreach ( var animClip in animClips ) {
2447
- if ( clipSet . ContainsKey ( animClip ) ) {
2462
+ if ( exportData . animationClips . ContainsKey ( animClip ) ) {
2448
2463
// we have already exported gameobjects for this clip
2449
2464
continue ;
2450
2465
}
2451
2466
2452
- clipSet . Add ( animClip , animationRootObject ) ;
2467
+ exportData . animationClips . Add ( animClip , animationRootObject ) ;
2453
2468
2454
2469
foreach ( EditorCurveBinding uniCurveBinding in AnimationUtility . GetCurveBindings ( animClip ) ) {
2455
2470
Object uniObj = AnimationUtility . GetAnimatedObject ( animationRootObject , uniCurveBinding ) ;
@@ -2464,12 +2479,12 @@ protected void GetObjectsInAnimationClips(
2464
2479
}
2465
2480
2466
2481
if ( lightProps . Contains ( uniCurveBinding . propertyName ) ) {
2467
- exportComponent . Add ( unityGo , typeof ( Light ) ) ;
2482
+ exportData . exportComponent . Add ( unityGo , typeof ( Light ) ) ;
2468
2483
} else if ( cameraProps . Contains ( uniCurveBinding . propertyName ) ) {
2469
- exportComponent . Add ( unityGo , typeof ( Camera ) ) ;
2484
+ exportData . exportComponent . Add ( unityGo , typeof ( Camera ) ) ;
2470
2485
}
2471
2486
2472
- goToExport . Add ( unityGo ) ;
2487
+ exportData . goExportSet . Add ( unityGo ) ;
2473
2488
}
2474
2489
}
2475
2490
}
0 commit comments