@@ -2513,7 +2513,7 @@ protected Dictionary<GameObject, AnimationOnlyExportData> GetAnimationExportData
2513
2513
/// Transform components have already been exported.
2514
2514
/// This function exports the other components and animation.
2515
2515
/// </summary>
2516
- protected bool ExportComponents ( FbxScene fbxScene , AnimationExportType animationExportType = AnimationExportType . all )
2516
+ protected bool ExportComponents ( FbxScene fbxScene , bool exportAnim = true )
2517
2517
{
2518
2518
var animationNodes = new HashSet < GameObject > ( ) ;
2519
2519
@@ -2552,7 +2552,7 @@ protected bool ExportComponents(FbxScene fbxScene, AnimationExportType animation
2552
2552
2553
2553
// check if this object contains animation, keep track of it
2554
2554
// if it does
2555
- if ( animationExportType != AnimationExportType . none && GameObjectHasAnimation ( unityGo ) ) {
2555
+ if ( exportAnim && GameObjectHasAnimation ( unityGo ) ) {
2556
2556
animationNodes . Add ( unityGo ) ;
2557
2557
}
2558
2558
}
@@ -2719,8 +2719,7 @@ public enum TransformExportType { Local, Global, Reset };
2719
2719
/// </summary>
2720
2720
public int ExportAll (
2721
2721
IEnumerable < UnityEngine . Object > unityExportSet ,
2722
- Dictionary < GameObject , AnimationOnlyExportData > animationExportData ,
2723
- AnimationExportType animationExportType = AnimationExportType . all )
2722
+ Dictionary < GameObject , AnimationOnlyExportData > animationExportData )
2724
2723
{
2725
2724
exportCancelled = false ;
2726
2725
@@ -2861,7 +2860,7 @@ public int ExportAll (
2861
2860
}
2862
2861
2863
2862
if ( ! animOnly ) {
2864
- if ( ! ExportComponents ( fbxScene , animationExportType ) ) {
2863
+ if ( ! ExportComponents ( fbxScene , ExportOptions . GetModelAnimIncludeOption ( ) != ExportModelSettingsSerialize . Include . Model ) ) {
2865
2864
Debug . LogWarning ( "Export Cancelled" ) ;
2866
2865
return 0 ;
2867
2866
}
@@ -3012,11 +3011,11 @@ public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, G
3012
3011
} ;
3013
3012
3014
3013
if ( ! string . IsNullOrEmpty ( filePath ) ) {
3015
- ExportObjects ( filePath , myArray , animExportType : AnimationExportType . timelineAnimationClip ) ;
3014
+ ExportObjects ( filePath , myArray , timelineAnim : true ) ;
3016
3015
return ;
3017
3016
}
3018
3017
3019
- ExportModelEditorWindow . Init ( myArray , string . Format ( "{0}@{1}" , animationTrackGObject . name , timelineClipSelected . displayName ) , AnimationExportType . timelineAnimationClip ) ;
3018
+ ExportModelEditorWindow . Init ( myArray , string . Format ( "{0}@{1}" , animationTrackGObject . name , timelineClipSelected . displayName ) , isTimelineAnim : true ) ;
3020
3019
}
3021
3020
3022
3021
/// <summary>
@@ -3025,19 +3024,6 @@ public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, G
3025
3024
[ MenuItem ( ClipMenuItemName , false , 31 ) ]
3026
3025
public static void OnPlayableDirectorGameObjectContextClick ( MenuCommand command )
3027
3026
{
3028
- // Now that we know we have stuff to export, get the user-desired path.
3029
- string directory = string . IsNullOrEmpty ( LastFilePath )
3030
- ? Application . dataPath
3031
- : System . IO . Path . GetDirectoryName ( LastFilePath ) ;
3032
-
3033
- string title = "Select the folder in which the animation files from the timeline will be exported" ;
3034
- string folderPath = EditorUtility . SaveFolderPanel ( title , directory , "" ) ;
3035
-
3036
- if ( string . IsNullOrEmpty ( folderPath ) )
3037
- {
3038
- return ;
3039
- }
3040
-
3041
3027
Object [ ] selection = null ;
3042
3028
3043
3029
if ( command == null || command . context == null )
@@ -3057,28 +3043,32 @@ public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
3057
3043
3058
3044
foreach ( GameObject objectWithPlayableDirector in selection )
3059
3045
{
3060
- ExportAllTimelineClips ( objectWithPlayableDirector , folderPath ) ;
3046
+ if ( ExportAllTimelineClips ( objectWithPlayableDirector ) ) {
3047
+ return ;
3048
+ }
3061
3049
}
3062
3050
}
3063
3051
3064
- public static void ExportAllTimelineClips ( GameObject objectWithPlayableDirector , string folderPath )
3052
+ public static bool ExportAllTimelineClips ( GameObject objectWithPlayableDirector , string folderPath = null )
3065
3053
{
3066
3054
PlayableDirector pd = objectWithPlayableDirector . GetComponent < PlayableDirector > ( ) ;
3067
- if ( pd ! = null )
3055
+ if ( pd = = null )
3068
3056
{
3069
- foreach ( PlayableBinding output in pd . playableAsset . outputs )
3070
- {
3071
- AnimationTrack at = output . sourceObject as AnimationTrack ;
3072
-
3073
- GameObject atObject = pd . GetGenericBinding ( output . sourceObject ) as GameObject ;
3074
- // One file by animation clip
3075
- foreach ( TimelineClip timeLineClip in at . GetClips ( ) ) {
3076
- string filePath = string . Format ( AnimFbxFileFormat , folderPath , atObject . name , timeLineClip . displayName ) ;
3077
- UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { atObject , timeLineClip . animationClip } ;
3078
- //ExportObjects (filePath, myArray, AnimationExportType.timelineAnimationClip);
3079
- }
3057
+ return false ;
3058
+ }
3059
+ foreach ( PlayableBinding output in pd . playableAsset . outputs )
3060
+ {
3061
+ AnimationTrack at = output . sourceObject as AnimationTrack ;
3062
+
3063
+ GameObject atObject = pd . GetGenericBinding ( output . sourceObject ) as GameObject ;
3064
+ // One file by animation clip
3065
+ foreach ( TimelineClip timeLineClip in at . GetClips ( ) ) {
3066
+ string filePath = string . Format ( AnimFbxFileFormat , folderPath , atObject . name , timeLineClip . displayName ) ;
3067
+ UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { atObject , timeLineClip . animationClip } ;
3068
+ ExportObjects ( filePath , myArray , timelineAnim : true ) ;
3080
3069
}
3081
3070
}
3071
+ return true ;
3082
3072
}
3083
3073
3084
3074
/// <summary>
@@ -3128,21 +3118,7 @@ public static bool OnValidateMenuItem ()
3128
3118
{
3129
3119
return true ;
3130
3120
}
3131
-
3132
- /// <summary>
3133
- /// Add a menu item "Export Model Only..." to a GameObject's context menu.
3134
- /// </summary>
3135
- /// <param name="command">Command.</param>
3136
- [ MenuItem ( ModelOnlyMenuItemName , false , 30 ) ]
3137
- static void ModelOnlyOnContextItem ( MenuCommand command )
3138
- {
3139
- if ( Selection . objects . Length <= 0 ) {
3140
- DisplayNoSelectionDialog ( ) ;
3141
- return ;
3142
- }
3143
- OnExport ( AnimationExportType . none ) ;
3144
- }
3145
-
3121
+
3146
3122
/// <summary>
3147
3123
/// Validate the menu item defined by the function above.
3148
3124
/// </summary>
@@ -3152,22 +3128,6 @@ public static bool ModelOnlyOnValidateMenuItem ()
3152
3128
return true ;
3153
3129
}
3154
3130
3155
-
3156
- /// <summary>
3157
- /// Add a menu item "Export Animation Only" to a GameObject's context menu.
3158
- /// </summary>
3159
- /// <param name="command">Command.</param>
3160
- [ MenuItem ( AnimOnlyMenuItemName , false , 30 ) ]
3161
- static void OnAnimOnlyContextItem ( MenuCommand command )
3162
- {
3163
- if ( Selection . objects . Length <= 0 ) {
3164
- DisplayNoSelectionDialog ( ) ;
3165
- return ;
3166
- }
3167
-
3168
- OnExport ( AnimationExportType . componentAnimation ) ;
3169
- }
3170
-
3171
3131
/// <summary>
3172
3132
// Validate the menu item defined by the function above.
3173
3133
/// </summary>
@@ -3623,15 +3583,6 @@ public void Dispose ()
3623
3583
3624
3584
const string kFBXFileExtension = "fbx" ;
3625
3585
3626
- public enum AnimationExportType {
3627
- timelineAnimationClip ,
3628
- timelineAnimationTrack ,
3629
- componentAnimation ,
3630
- all ,
3631
- none
3632
- }
3633
-
3634
-
3635
3586
private static string MakeFileName ( string basename = "test" , string extension = kFBXFileExtension )
3636
3587
{
3637
3588
return basename + "." + extension ;
@@ -3648,12 +3599,12 @@ private static string GetExportFilePath(string filenameSuggestion = ""){
3648
3599
return EditorUtility . SaveFilePanel ( title , directory , filenameSuggestion , kFBXFileExtension ) ;
3649
3600
}
3650
3601
3651
- private static void OnExport ( AnimationExportType exportType = AnimationExportType . all )
3602
+ private static void OnExport ( )
3652
3603
{
3653
3604
GameObject [ ] selectedGOs = Selection . GetFiltered < GameObject > ( SelectionMode . TopLevel ) ;
3654
3605
3655
3606
var toExport = ModelExporter . RemoveRedundantObjects ( selectedGOs ) ;
3656
- ExportModelEditorWindow . Init ( System . Linq . Enumerable . Cast < UnityEngine . Object > ( toExport ) , exportType : exportType ) ;
3607
+ ExportModelEditorWindow . Init ( System . Linq . Enumerable . Cast < UnityEngine . Object > ( toExport ) , isTimelineAnim : false ) ;
3657
3608
}
3658
3609
3659
3610
/// <summary>
@@ -3664,7 +3615,7 @@ public static string ExportObjects (
3664
3615
string filePath ,
3665
3616
UnityEngine . Object [ ] objects = null ,
3666
3617
IExportOptions exportOptions = null ,
3667
- AnimationExportType animExportType = AnimationExportType . all )
3618
+ bool timelineAnim = false )
3668
3619
{
3669
3620
LastFilePath = filePath ;
3670
3621
@@ -3678,34 +3629,25 @@ public static string ExportObjects (
3678
3629
}
3679
3630
3680
3631
Dictionary < GameObject , AnimationOnlyExportData > animationExportData = null ;
3681
- switch ( animExportType )
3682
- {
3683
- case AnimationExportType . timelineAnimationClip :
3632
+ if ( exportOptions . GetModelAnimIncludeOption ( ) == ExportModelSettingsSerialize . Include . Anim ) {
3633
+ if ( timelineAnim ) {
3684
3634
// We expect the first argument in the list to be the GameObject, the second one is the Animation Clip/Track we are exporting from the timeline
3685
- GameObject rootObject = ModelExporter . GetGameObject ( objects [ 0 ] ) ;
3686
- AnimationClip timelineClip = objects [ 1 ] as AnimationClip ;
3687
- List < AnimationClip > clipList = new List < AnimationClip > ( ) ;
3688
- clipList . Add ( timelineClip ) ;
3689
- animationExportData = fbxExporter . GetTimelineAnimationExportData ( rootObject , clipList ) ;
3690
- break ;
3691
- case AnimationExportType . timelineAnimationTrack :
3692
- GameObject rootObject2 = ModelExporter . GetGameObject ( objects [ 0 ] ) ;
3693
- AnimationTrack timelineTrack = objects [ 1 ] as AnimationTrack ;
3694
- animationExportData = fbxExporter . GetAnimationExportDataFromAnimationTrack ( rootObject2 , timelineTrack ) ;
3695
- break ;
3696
- case AnimationExportType . componentAnimation :
3697
- HashSet < GameObject > gos = new HashSet < GameObject > ( ) ;
3698
- foreach ( var obj in objects )
3699
- {
3700
- gos . Add ( ModelExporter . GetGameObject ( obj ) ) ;
3635
+ GameObject rootObject = ModelExporter . GetGameObject ( objects [ 0 ] ) ;
3636
+ AnimationClip timelineClip = objects [ 1 ] as AnimationClip ;
3637
+ List < AnimationClip > clipList = new List < AnimationClip > ( ) ;
3638
+ clipList . Add ( timelineClip ) ;
3639
+ animationExportData = fbxExporter . GetTimelineAnimationExportData ( rootObject , clipList ) ;
3640
+ }
3641
+ else {
3642
+ HashSet < GameObject > gos = new HashSet < GameObject > ( ) ;
3643
+ foreach ( var obj in objects ) {
3644
+ gos . Add ( ModelExporter . GetGameObject ( obj ) ) ;
3701
3645
}
3702
- animationExportData = fbxExporter . GetAnimationExportData ( gos ) ;
3703
- break ;
3704
- default :
3705
- break ;
3646
+ animationExportData = fbxExporter . GetAnimationExportData ( gos ) ;
3647
+ }
3706
3648
}
3707
3649
3708
- if ( fbxExporter . ExportAll ( objects , animationExportData , animExportType ) > 0 ) {
3650
+ if ( fbxExporter . ExportAll ( objects , animationExportData ) > 0 ) {
3709
3651
string message = string . Format ( "Successfully exported: {0}" , filePath ) ;
3710
3652
UnityEngine . Debug . Log ( message ) ;
3711
3653
@@ -3718,9 +3660,9 @@ public static string ExportObjects (
3718
3660
public static string ExportObject (
3719
3661
string filePath , UnityEngine . Object root ,
3720
3662
IExportOptions exportOptions = null ,
3721
- AnimationExportType exportType = AnimationExportType . all )
3663
+ bool isTimelineAnim = false )
3722
3664
{
3723
- return ExportObjects ( filePath , new Object [ ] { root } , exportOptions , animExportType : exportType ) ;
3665
+ return ExportObjects ( filePath , new Object [ ] { root } , exportOptions , isTimelineAnim ) ;
3724
3666
}
3725
3667
3726
3668
private static void EnsureDirectory ( string path )
0 commit comments