@@ -82,6 +82,8 @@ public class ModelExporter : System.IDisposable
82
82
const string MenuItemName = "GameObject/Export Model..." ;
83
83
84
84
const string ClipMenuItemName = "GameObject/Export All Recorded Animation Clips..." ;
85
+ const string TimelineClipMenuItemName = "GameObject/Export Selected Timeline Clip..." ;
86
+
85
87
86
88
const string AnimOnlyMenuItemName = "GameObject/Export Animation Only" ;
87
89
@@ -2497,7 +2499,7 @@ protected int GetAnimOnlyHierarchyCount(HashSet<GameObject> exportSet, Dictionar
2497
2499
return completeExpSet . Count ;
2498
2500
}
2499
2501
2500
- protected Dictionary < GameObject , AnimationOnlyExportData > GetTimelineAnimationExportData ( GameObject rootObject , AnimationTrack animationTrack )
2502
+ protected Dictionary < GameObject , AnimationOnlyExportData > GetAnimationExportDataFromAnimationTrack ( GameObject rootObject , AnimationTrack animationTrack )
2501
2503
{
2502
2504
// get animation clips for root object from animation track
2503
2505
List < AnimationClip > clips = new List < AnimationClip > ( ) ;
@@ -2507,12 +2509,18 @@ protected Dictionary<GameObject, AnimationOnlyExportData> GetTimelineAnimationEx
2507
2509
clips . Add ( myclip . animationClip ) ;
2508
2510
}
2509
2511
2512
+ return GetTimelineAnimationExportData ( rootObject , clips ) ;
2513
+ }
2514
+
2515
+
2516
+ protected Dictionary < GameObject , AnimationOnlyExportData > GetTimelineAnimationExportData ( GameObject rootObject , List < AnimationClip > animationClipsList )
2517
+ {
2510
2518
var goToExport = new HashSet < GameObject > ( ) ;
2511
2519
var animationClips = new Dictionary < AnimationClip , GameObject > ( ) ;
2512
2520
var exportComponent = new Dictionary < GameObject , System . Type > ( ) ;
2513
2521
2514
2522
var exportData = new AnimationOnlyExportData ( animationClips , goToExport , exportComponent ) ;
2515
- exportData . ComputeObjectsInAnimationClips ( clips . ToArray ( ) , rootObject ) ;
2523
+ exportData . ComputeObjectsInAnimationClips ( animationClipsList . ToArray ( ) , rootObject ) ;
2516
2524
2517
2525
Dictionary < GameObject , AnimationOnlyExportData > data = new Dictionary < GameObject , AnimationOnlyExportData > ( ) ;
2518
2526
data . Add ( rootObject , exportData ) ;
@@ -3048,11 +3056,56 @@ private void ReplaceFile ()
3048
3056
}
3049
3057
}
3050
3058
3059
+ [ MenuItem ( TimelineClipMenuItemName , false , 31 ) ]
3060
+ static void OnClipContextClick ( MenuCommand command )
3061
+ {
3062
+ // Now that we know we have stuff to export, get the user-desired path.
3063
+ string directory = string . IsNullOrEmpty ( LastFilePath )
3064
+ ? Application . dataPath
3065
+ : System . IO . Path . GetDirectoryName ( LastFilePath ) ;
3066
+
3067
+ string title = "Select the folder in which the animation files from the timeline will be exported" ;
3068
+ string folderPath = EditorUtility . SaveFolderPanel ( title , directory , "" ) ;
3069
+
3070
+ if ( string . IsNullOrEmpty ( folderPath ) )
3071
+ {
3072
+ return ;
3073
+ }
3074
+ Debug . Log ( folderPath ) ;
3075
+
3076
+
3077
+ var selectedObjects = Selection . objects ;
3078
+ foreach ( var obj in selectedObjects )
3079
+ {
3080
+ if ( obj . GetType ( ) . Name . Contains ( "EditorClip" ) )
3081
+ {
3082
+ var selClip = obj . GetType ( ) . GetProperty ( "clip" ) . GetValue ( obj , null ) ;
3083
+ UnityEngine . Timeline . TimelineClip timeLineClip = selClip as UnityEngine . Timeline . TimelineClip ;
3084
+
3085
+ var selClipItem = obj . GetType ( ) . GetProperty ( "item" ) . GetValue ( obj , null ) ;
3086
+ var selClipItemParentTrack = selClipItem . GetType ( ) . GetProperty ( "parentTrack" ) . GetValue ( selClipItem , null ) ;
3087
+ AnimationTrack editorClipAnimationTrack = selClipItemParentTrack as AnimationTrack ;
3088
+
3089
+ GameObject animationTrackGObject = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( editorClipAnimationTrack ) as GameObject ;
3090
+
3091
+ Debug . Log ( "obj name: " + obj . name + " /clip name: " + editorClipAnimationTrack . name + " /timelineAssetName: " + animationTrackGObject . name ) ;
3092
+
3093
+ string filePath = folderPath + "/" + animationTrackGObject . name + "@" + timeLineClip . animationClip . name + ".fbx" ;
3094
+ Debug . Log ( "filepath: " + filePath ) ;
3095
+ UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { animationTrackGObject , timeLineClip . animationClip } ;
3096
+
3097
+ ExportObjects ( filePath , myArray , ExportType . timelineAnimationClip ) ;
3098
+ }
3099
+ }
3100
+ }
3101
+
3102
+
3103
+
3051
3104
/// <summary>
3052
3105
/// Add an option "Update from FBX" in the contextual GameObject menu.
3053
3106
/// </summary>
3054
3107
[ MenuItem ( ClipMenuItemName , false , 31 ) ]
3055
- static void OnClipContextClick ( MenuCommand command )
3108
+ static void OnGameObjectWithTimelineContextClick ( MenuCommand command )
3056
3109
{
3057
3110
// Now that we know we have stuff to export, get the user-desired path.
3058
3111
string directory = string . IsNullOrEmpty ( LastFilePath )
@@ -3102,12 +3155,11 @@ static void OnClipContextClick(MenuCommand command)
3102
3155
Debug . Log ( "filepath: " + filePath ) ;
3103
3156
UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { atObject , at } ;
3104
3157
3105
- ExportObjects ( filePath , myArray , ExportType . timelineAnimation ) ;
3158
+ ExportObjects ( filePath , myArray , ExportType . timelineAnimationTrack ) ;
3106
3159
}
3107
3160
}
3108
3161
}
3109
3162
}
3110
-
3111
3163
3112
3164
/// <summary>
3113
3165
/// Validate the menu item defined by the function above.
@@ -3124,9 +3176,10 @@ public static bool ValidateClipContextClick()
3124
3176
return false ;
3125
3177
}
3126
3178
3127
- foreach ( GameObject obj in selection )
3179
+ foreach ( Object obj in selection )
3128
3180
{
3129
- if ( obj . GetComponent < PlayableDirector > ( ) != null )
3181
+ GameObject gameObj = obj as GameObject ;
3182
+ if ( gameObj != null && gameObj . GetComponent < PlayableDirector > ( ) != null )
3130
3183
{
3131
3184
return true ;
3132
3185
}
@@ -3622,7 +3675,8 @@ public void Dispose ()
3622
3675
const string Extension = "fbx" ;
3623
3676
3624
3677
public enum ExportType {
3625
- timelineAnimation ,
3678
+ timelineAnimationClip ,
3679
+ timelineAnimationTrack ,
3626
3680
componentAnimation ,
3627
3681
all
3628
3682
}
@@ -3685,10 +3739,17 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
3685
3739
Dictionary < GameObject , AnimationOnlyExportData > animationExportData = null ;
3686
3740
switch ( exportType )
3687
3741
{
3688
- case ExportType . timelineAnimation :
3742
+ case ExportType . timelineAnimationClip :
3689
3743
GameObject rootObject = ModelExporter . GetGameObject ( objects [ 0 ] ) ;
3744
+ AnimationClip timelineClip = objects [ 1 ] as AnimationClip ;
3745
+ List < AnimationClip > clipList = new List < AnimationClip > ( ) ;
3746
+ clipList . Add ( timelineClip ) ;
3747
+ animationExportData = fbxExporter . GetTimelineAnimationExportData ( rootObject , clipList ) ;
3748
+ break ;
3749
+ case ExportType . timelineAnimationTrack :
3750
+ GameObject rootObject2 = ModelExporter . GetGameObject ( objects [ 0 ] ) ;
3690
3751
AnimationTrack timelineTrack = objects [ 1 ] as AnimationTrack ;
3691
- animationExportData = fbxExporter . GetTimelineAnimationExportData ( rootObject , timelineTrack ) ;
3752
+ animationExportData = fbxExporter . GetAnimationExportDataFromAnimationTrack ( rootObject2 , timelineTrack ) ;
3692
3753
break ;
3693
3754
case ExportType . componentAnimation :
3694
3755
HashSet < GameObject > gos = new HashSet < GameObject > ( ) ;
0 commit comments