@@ -83,7 +83,7 @@ public class ModelExporter : System.IDisposable
8383 // being called only once regardless of what is selected.
8484 const string MenuItemName = "GameObject/Export Model..." ;
8585
86- const string ClipMenuItemName = "GameObject/Export All Timeline Clips..." ;
86+ const string ClipMenuItemName = "GameObject/Export All Recorded Animation Clips..." ;
8787 const string TimelineClipMenuItemName = "GameObject/Export Selected Timeline Clip..." ;
8888
8989 const string AnimOnlyMenuItemName = "GameObject/Export Animation Only..." ;
@@ -2945,45 +2945,62 @@ private void ReplaceFile ()
29452945 }
29462946
29472947 /// <summary>
2948- /// Add an option " Export selected Timeline clip" in the contextual GameObject menu .
2948+ /// GameObject/ Export Selected Timeline Clip.. .
29492949 /// </summary>
2950- [ MenuItem ( TimelineClipMenuItemName , false , 31 ) ]
2950+ /// <param name="command"></param>
2951+ [ MenuItem ( TimelineClipMenuItemName , false , 31 ) ]
29512952 static void OnClipContextClick ( MenuCommand command )
29522953 {
2953- var selectedObjects = Selection . objects ;
2954- foreach ( var obj in selectedObjects )
2954+ // Now that we know we have stuff to export, get the user-desired path.
2955+ string directory = string . IsNullOrEmpty ( LastFilePath )
2956+ ? Application . dataPath
2957+ : System . IO . Path . GetDirectoryName ( LastFilePath ) ;
2958+
2959+ string title = "Select the folder in which the animation files from the timeline will be exported" ;
2960+ string folderPath = EditorUtility . SaveFolderPanel ( title , directory , "" ) ;
2961+
2962+ if ( string . IsNullOrEmpty ( folderPath ) )
29552963 {
2956- if ( obj . GetType ( ) . Name . Contains ( "EditorClip" ) )
2957- {
2958- var timeLineClip = GetPropertyFromObject < TimelineClip > ( obj , "clip" ) ;
2964+ return ;
2965+ }
2966+ Debug . Log ( folderPath ) ;
29592967
2960- var selClipItem = GetPropertyFromObject < object > ( obj , "item" ) ;
2961- var editorClipAnimationTrack = GetPropertyFromObject < AnimationTrack > ( selClipItem , "parentTrack" ) ;
2968+ Object [ ] selectedObjects = Selection . objects ;
29622969
2963- GameObject animationTrackGObject = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( editorClipAnimationTrack ) as GameObject ;
2970+ foreach ( Object editorClipSelected in selectedObjects )
2971+ {
2972+ ExportSingleEditorClip ( editorClipSelected , folderPath ) ;
2973+ }
2974+ }
29642975
2965- string filePath = GetExportFilePath ( animationTrackGObject . name + "@" + timeLineClip . displayName ) ;
2966- if ( string . IsNullOrEmpty ( filePath ) ) {
2967- continue ;
2968- }
2976+ public static void ExportSingleEditorClip ( Object editorClipSelected , string folderPath )
2977+ {
2978+ if ( editorClipSelected . GetType ( ) . Name . Contains ( "EditorClip" ) )
2979+ {
2980+ object selClip = editorClipSelected . GetType ( ) . GetProperty ( "clip" ) . GetValue ( editorClipSelected , null ) ;
2981+ UnityEngine . Timeline . TimelineClip timeLineClip = selClip as UnityEngine . Timeline . TimelineClip ;
29692982
2970- UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { animationTrackGObject , timeLineClip . animationClip } ;
2983+ object selClipItem = editorClipSelected . GetType ( ) . GetProperty ( "item" ) . GetValue ( editorClipSelected , null ) ;
2984+ object selClipItemParentTrack = selClipItem . GetType ( ) . GetProperty ( "parentTrack" ) . GetValue ( selClipItem , null ) ;
2985+ AnimationTrack editorClipAnimationTrack = selClipItemParentTrack as AnimationTrack ;
2986+ GameObject animationTrackGObject = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( editorClipAnimationTrack ) as GameObject ;
29712987
2972- ExportObjects ( filePath , myArray , AnimationExportType . timelineAnimationClip ) ;
2973- return ;
2974- }
2975- }
2988+ ExportSingleTimelineClip ( timeLineClip , folderPath , animationTrackGObject ) ;
2989+ }
29762990 }
29772991
2978- private static T GetPropertyFromObject < T > ( object obj , string propertyName ) where T : class {
2979- return obj . GetType ( ) . GetProperty ( propertyName ) . GetValue ( obj , null ) as T ;
2992+ public static void ExportSingleTimelineClip ( TimelineClip timelineClipSelected , string folderPath , GameObject animationTrackGObject )
2993+ {
2994+ string filePath = GetExportFilePath ( animationTrackGObject . name + "@" + timeLineClip . displayName ) ;
2995+ UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { animationTrackGObject , timelineClipSelected . animationClip } ;
2996+ ExportObjects ( filePath , myArray , AnimationExportType . timelineAnimationClip ) ;
29802997 }
29812998
29822999 /// <summary>
2983- /// Add an option "Export all Timeline clips " in the contextual GameObject menu.
3000+ /// Add an option " GameObject/ Export All Recorded Animation Clips... " in the contextual GameObject menu.
29843001 /// </summary>
29853002 [ MenuItem ( ClipMenuItemName , false , 31 ) ]
2986- static void OnGameObjectWithTimelineContextClick ( MenuCommand command )
3003+ public static void OnPlayableDirectorGameObjectContextClick ( MenuCommand command )
29873004 {
29883005 // Now that we know we have stuff to export, get the user-desired path.
29893006 string directory = string . IsNullOrEmpty ( LastFilePath )
@@ -3008,21 +3025,29 @@ static void OnGameObjectWithTimelineContextClick(MenuCommand command)
30083025 else
30093026 {
30103027 // We were invoked from the right-click menu, so use the context of the context menu.
3011- var selected = command . context as GameObject ;
3028+ GameObject selected = command . context as GameObject ;
30123029 if ( selected )
30133030 {
30143031 selection = new GameObject [ ] { selected } ;
30153032 }
30163033 }
30173034
3018- foreach ( GameObject obj in selection )
3035+ foreach ( GameObject objectWithPlayableDirector in selection )
30193036 {
3020- PlayableDirector pd = obj . GetComponent < PlayableDirector > ( ) ;
3021- if ( pd != null )
3037+ ExportAllTimelineClips ( objectWithPlayableDirector , folderPath ) ;
3038+ }
3039+ }
3040+
3041+ public static void ExportAllTimelineClips ( GameObject objectWithPlayableDirector , string folderPath )
3042+ {
3043+ Debug . Log ( objectWithPlayableDirector . GetType ( ) . BaseType . ToString ( ) + ":" + objectWithPlayableDirector . name ) ;
3044+
3045+ PlayableDirector pd = objectWithPlayableDirector . GetComponent < PlayableDirector > ( ) ;
3046+ if ( pd != null )
3047+ {
3048+ foreach ( PlayableBinding output in pd . playableAsset . outputs )
30223049 {
3023- foreach ( PlayableBinding output in pd . playableAsset . outputs )
3024- {
3025- AnimationTrack at = output . sourceObject as AnimationTrack ;
3050+ AnimationTrack at = output . sourceObject as AnimationTrack ;
30263051
30273052 GameObject atObject = pd . GetGenericBinding ( output . sourceObject ) as GameObject ;
30283053 // One file by animation clip
@@ -3581,7 +3606,6 @@ private static string GetExportFilePath(string filenameSuggestion = ""){
35813606
35823607 private static void OnExport ( AnimationExportType exportType = AnimationExportType . all )
35833608 {
3584-
35853609 // Now that we know we have stuff to export, get the user-desired path.
35863610 GameObject [ ] selectedGOs = Selection . GetFiltered < GameObject > ( SelectionMode . TopLevel ) ;
35873611 string filename = null ;
@@ -3610,6 +3634,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
36103634 /// Export a list of (Game) objects to FBX file.
36113635 /// Use the SaveFile panel to allow user to enter a file name.
36123636 /// <summary>
3637+ //public static string ExportObjects (string filePath, UnityEngine.Object[] objects = null, AnimationExportType exportType = AnimationExportType.all /*, bool animOnly = false*/)
36133638 public static string ExportObjects (
36143639 string filePath ,
36153640 UnityEngine . Object [ ] objects = null ,
@@ -3666,6 +3691,7 @@ public static string ExportObjects (
36663691 return null ;
36673692 }
36683693
3694+ //public static string ExportObject (string filePath, UnityEngine.Object root, AnimationExportType exportType = AnimationExportType.all /*, bool animOnly = false*/)
36693695 public static string ExportObject (
36703696 string filePath , UnityEngine . Object root ,
36713697 AnimationExportType exportType = AnimationExportType . all ,
0 commit comments