@@ -80,6 +80,8 @@ public class ModelExporter : System.IDisposable
80
80
// being called only once regardless of what is selected.
81
81
const string MenuItemName = "GameObject/Export Model..." ;
82
82
83
+ const string AnimOnlyMenuItemName = "GameObject/Export Animation Only" ;
84
+
83
85
const string FileBaseName = "Untitled" ;
84
86
85
87
const string ProgressBarTitle = "Fbx Export" ;
@@ -2722,7 +2724,7 @@ public enum TransformExportType { Local, Global, Reset };
2722
2724
///
2723
2725
/// This refreshes the asset database.
2724
2726
/// </summary>
2725
- public int ExportAll ( IEnumerable < UnityEngine . Object > unityExportSet )
2727
+ public int ExportAll ( IEnumerable < UnityEngine . Object > unityExportSet , bool animOnly = false )
2726
2728
{
2727
2729
exportCancelled = false ;
2728
2730
@@ -2809,7 +2811,15 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
2809
2811
// stores how many objects we have exported, -1 if export was cancelled
2810
2812
int exportProgress = 0 ;
2811
2813
var revisedExportSet = RemoveRedundantObjects ( unityExportSet ) ;
2812
- int count = GetHierarchyCount ( revisedExportSet ) ;
2814
+
2815
+ Dictionary < GameObject , AnimationOnlyExportData > exportData ;
2816
+ int count = 0 ;
2817
+ if ( animOnly ) {
2818
+ count = GetAnimOnlyHierarchyCount ( revisedExportSet , out exportData ) ;
2819
+ } else {
2820
+ count = GetHierarchyCount ( revisedExportSet ) ;
2821
+ exportData = new Dictionary < GameObject , AnimationOnlyExportData > ( ) ;
2822
+ }
2813
2823
2814
2824
Vector3 center = Vector3 . zero ;
2815
2825
var exportType = TransformExportType . Reset ;
@@ -2819,42 +2829,25 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
2819
2829
}
2820
2830
2821
2831
foreach ( var unityGo in revisedExportSet ) {
2822
- exportProgress = this . ExportTransformHierarchy ( unityGo , fbxScene , fbxRootNode ,
2823
- exportProgress , count , center , exportType ) ;
2832
+ AnimationOnlyExportData data ;
2833
+ if ( animOnly && exportData . TryGetValue ( unityGo , out data ) ) {
2834
+ exportProgress = this . ExportAnimationOnly ( unityGo , fbxScene , exportProgress , count , center , data , exportType ) ;
2835
+ }
2836
+ else {
2837
+ exportProgress = this . ExportTransformHierarchy ( unityGo , fbxScene , fbxRootNode ,
2838
+ exportProgress , count , center , exportType ) ;
2839
+ }
2824
2840
if ( exportCancelled || exportProgress < 0 ) {
2825
2841
Debug . LogWarning ( "Export Cancelled" ) ;
2826
2842
return 0 ;
2827
2843
}
2828
2844
}
2829
2845
2830
- /*if(revisedExportSet.Count == 1){
2831
- foreach(var unityGo in revisedExportSet){
2832
- exportProgress = this.ExportTransformHierarchy (
2833
- unityGo, fbxScene, fbxRootNode, exportProgress,
2834
- count, Vector3.zero, TransformExportType.Reset);
2835
- if (exportCancelled || exportProgress < 0) {
2836
- Debug.LogWarning ("Export Cancelled");
2837
- return 0;
2838
- }
2839
- }
2840
- }
2841
- else{
2842
- // find the center of the export set
2843
- Vector3 center = ExportSettings.centerObjects? FindCenter(revisedExportSet) : Vector3.zero;
2844
-
2845
- foreach (var unityGo in revisedExportSet) {
2846
- exportProgress = this.ExportTransformHierarchy (unityGo, fbxScene, fbxRootNode,
2847
- exportProgress, count, center, TransformExportType.Global);
2848
- if (exportCancelled || exportProgress < 0) {
2849
- Debug.LogWarning ("Export Cancelled");
2850
- return 0;
2851
- }
2846
+ if ( ! animOnly ) {
2847
+ if ( ! ExportComponents ( fbxScene ) ) {
2848
+ Debug . LogWarning ( "Export Cancelled" ) ;
2849
+ return 0 ;
2852
2850
}
2853
- }*/
2854
-
2855
- if ( ! ExportComponents ( fbxScene ) ) {
2856
- Debug . LogWarning ( "Export Cancelled" ) ;
2857
- return 0 ;
2858
2851
}
2859
2852
2860
2853
// Set the scene's default camera.
@@ -2981,6 +2974,29 @@ public static bool OnValidateMenuItem ()
2981
2974
return true ;
2982
2975
}
2983
2976
2977
+ /// <summary>
2978
+ /// Add a menu item to a GameObject's context menu.
2979
+ /// </summary>
2980
+ /// <param name="command">Command.</param>
2981
+ [ MenuItem ( AnimOnlyMenuItemName , false , 30 ) ]
2982
+ static void OnAnimOnlyContextItem ( MenuCommand command )
2983
+ {
2984
+ if ( Selection . objects . Length <= 0 ) {
2985
+ DisplayNoSelectionDialog ( ) ;
2986
+ return ;
2987
+ }
2988
+ OnExport ( animOnly : true ) ;
2989
+ }
2990
+
2991
+ /// <summary>
2992
+ // Validate the menu item defined by the function above.
2993
+ /// </summary>
2994
+ [ MenuItem ( AnimOnlyMenuItemName , true , 30 ) ]
2995
+ public static bool OnValidateAnimOnlyMenuItem ( )
2996
+ {
2997
+ return true ;
2998
+ }
2999
+
2984
3000
public static void DisplayNoSelectionDialog ( )
2985
3001
{
2986
3002
UnityEditor . EditorUtility . DisplayDialog (
@@ -3424,7 +3440,7 @@ private static string MakeFileName (string basename = "test", string extension =
3424
3440
return basename + "." + extension ;
3425
3441
}
3426
3442
3427
- private static void OnExport ( )
3443
+ private static void OnExport ( bool animOnly = false )
3428
3444
{
3429
3445
// Now that we know we have stuff to export, get the user-desired path.
3430
3446
var directory = string . IsNullOrEmpty ( LastFilePath )
@@ -3449,7 +3465,7 @@ private static void OnExport ()
3449
3465
return ;
3450
3466
}
3451
3467
3452
- if ( ExportObjects ( filePath ) != null ) {
3468
+ if ( ExportObjects ( filePath , animOnly : animOnly ) != null ) {
3453
3469
// refresh the asset database so that the file appears in the
3454
3470
// asset folder view.
3455
3471
AssetDatabase . Refresh ( ) ;
@@ -3460,7 +3476,7 @@ private static void OnExport ()
3460
3476
/// Export a list of (Game) objects to FBX file.
3461
3477
/// Use the SaveFile panel to allow user to enter a file name.
3462
3478
/// <summary>
3463
- public static string ExportObjects ( string filePath , UnityEngine . Object [ ] objects = null )
3479
+ public static string ExportObjects ( string filePath , UnityEngine . Object [ ] objects = null , bool animOnly = false )
3464
3480
{
3465
3481
LastFilePath = filePath ;
3466
3482
@@ -3472,7 +3488,7 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
3472
3488
objects = Selection . objects ;
3473
3489
}
3474
3490
3475
- if ( fbxExporter . ExportAll ( objects ) > 0 ) {
3491
+ if ( fbxExporter . ExportAll ( objects , animOnly ) > 0 ) {
3476
3492
string message = string . Format ( "Successfully exported: {0}" , filePath ) ;
3477
3493
UnityEngine . Debug . Log ( message ) ;
3478
3494
0 commit comments