@@ -83,7 +83,7 @@ public class ModelExporter : System.IDisposable
83
83
// being called only once regardless of what is selected.
84
84
const string MenuItemName = "GameObject/Export Model..." ;
85
85
86
- const string ClipMenuItemName = "GameObject/Export All Timeline Clips..." ;
86
+ const string ClipMenuItemName = "GameObject/Export All Recorded Animation Clips..." ;
87
87
const string TimelineClipMenuItemName = "GameObject/Export Selected Timeline Clip..." ;
88
88
89
89
const string AnimOnlyMenuItemName = "GameObject/Export Animation Only..." ;
@@ -2945,45 +2945,62 @@ private void ReplaceFile ()
2945
2945
}
2946
2946
2947
2947
/// <summary>
2948
- /// Add an option " Export selected Timeline clip" in the contextual GameObject menu .
2948
+ /// GameObject/ Export Selected Timeline Clip.. .
2949
2949
/// </summary>
2950
- [ MenuItem ( TimelineClipMenuItemName , false , 31 ) ]
2950
+ /// <param name="command"></param>
2951
+ [ MenuItem ( TimelineClipMenuItemName , false , 31 ) ]
2951
2952
static void OnClipContextClick ( MenuCommand command )
2952
2953
{
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 ) )
2955
2963
{
2956
- if ( obj . GetType ( ) . Name . Contains ( "EditorClip" ) )
2957
- {
2958
- var timeLineClip = GetPropertyFromObject < TimelineClip > ( obj , "clip" ) ;
2964
+ return ;
2965
+ }
2966
+ Debug . Log ( folderPath ) ;
2959
2967
2960
- var selClipItem = GetPropertyFromObject < object > ( obj , "item" ) ;
2961
- var editorClipAnimationTrack = GetPropertyFromObject < AnimationTrack > ( selClipItem , "parentTrack" ) ;
2968
+ Object [ ] selectedObjects = Selection . objects ;
2962
2969
2963
- GameObject animationTrackGObject = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( editorClipAnimationTrack ) as GameObject ;
2970
+ foreach ( Object editorClipSelected in selectedObjects )
2971
+ {
2972
+ ExportSingleEditorClip ( editorClipSelected , folderPath ) ;
2973
+ }
2974
+ }
2964
2975
2965
- string filePath = GetExportFilePath ( animationTrackGObject . name + "@" + timeLineClip . animationClip . name ) ;
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 ;
2969
2982
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 ;
2971
2987
2972
- ExportObjects ( filePath , myArray , AnimationExportType . timelineAnimationClip ) ;
2973
- return ;
2974
- }
2975
- }
2988
+ ExportSingleTimelineClip ( timeLineClip , folderPath , animationTrackGObject ) ;
2989
+ }
2976
2990
}
2977
2991
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 = folderPath + "/" + animationTrackGObject . name + "@" + timelineClipSelected . animationClip . name + ".fbx" ;
2995
+ UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { animationTrackGObject , timelineClipSelected . animationClip } ;
2996
+ ExportObjects ( filePath , myArray , AnimationExportType . timelineAnimationClip ) ;
2980
2997
}
2981
2998
2982
2999
/// <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.
2984
3001
/// </summary>
2985
3002
[ MenuItem ( ClipMenuItemName , false , 31 ) ]
2986
- static void OnGameObjectWithTimelineContextClick ( MenuCommand command )
3003
+ public static void OnPlayableDirectorGameObjectContextClick ( MenuCommand command )
2987
3004
{
2988
3005
// Now that we know we have stuff to export, get the user-desired path.
2989
3006
string directory = string . IsNullOrEmpty ( LastFilePath )
@@ -3008,31 +3025,38 @@ static void OnGameObjectWithTimelineContextClick(MenuCommand command)
3008
3025
else
3009
3026
{
3010
3027
// 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 ;
3012
3029
if ( selected )
3013
3030
{
3014
3031
selection = new GameObject [ ] { selected } ;
3015
3032
}
3016
3033
}
3017
3034
3018
- foreach ( GameObject obj in selection )
3035
+ foreach ( GameObject objectWithPlayableDirector in selection )
3019
3036
{
3020
- PlayableDirector pd = obj . GetComponent < PlayableDirector > ( ) ;
3021
- if ( pd != null )
3022
- {
3023
- foreach ( PlayableBinding output in pd . playableAsset . outputs )
3024
- {
3025
- AnimationTrack at = output . sourceObject as AnimationTrack ;
3037
+ ExportAllTimelineClips ( objectWithPlayableDirector , folderPath ) ;
3038
+ }
3039
+ }
3026
3040
3027
- GameObject atObject = pd . GetGenericBinding ( output . sourceObject ) as GameObject ;
3028
- // One file by animation clip
3029
- foreach ( TimelineClip timeLineClip in at . GetClips ( ) ) {
3030
- string filePath = string . Format ( AnimFbxFileFormat , folderPath , atObject . name , timeLineClip . animationClip . name ) ;
3031
- UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { atObject , timeLineClip . animationClip } ;
3032
- ExportObjects ( filePath , myArray , AnimationExportType . timelineAnimationClip ) ;
3041
+ public static void ExportAllTimelineClips ( GameObject objectWithPlayableDirector , string folderPath )
3042
+ {
3043
+ Debug . Log ( objectWithPlayableDirector . GetType ( ) . BaseType . ToString ( ) + ":" + objectWithPlayableDirector . name ) ;
3033
3044
3034
- }
3035
- }
3045
+ PlayableDirector pd = objectWithPlayableDirector . GetComponent < PlayableDirector > ( ) ;
3046
+ if ( pd != null )
3047
+ {
3048
+ foreach ( PlayableBinding output in pd . playableAsset . outputs )
3049
+ {
3050
+ AnimationTrack at = output . sourceObject as AnimationTrack ;
3051
+
3052
+ GameObject atObject = pd . GetGenericBinding ( output . sourceObject ) as GameObject ;
3053
+ // One file by animation clip
3054
+ foreach ( TimelineClip timeLineClip in at . GetClips ( ) )
3055
+ {
3056
+ string filePath = folderPath + "/" + atObject . name + "@" + timeLineClip . animationClip . name + ".fbx" ;
3057
+ UnityEngine . Object [ ] myArray = new UnityEngine . Object [ ] { atObject , timeLineClip . animationClip } ;
3058
+ ExportObjects ( filePath , myArray , AnimationExportType . timelineAnimationClip ) ;
3059
+ }
3036
3060
}
3037
3061
}
3038
3062
}
@@ -3581,7 +3605,6 @@ private static string GetExportFilePath(string filenameSuggestion = ""){
3581
3605
3582
3606
private static void OnExport ( AnimationExportType exportType = AnimationExportType . all )
3583
3607
{
3584
-
3585
3608
// Now that we know we have stuff to export, get the user-desired path.
3586
3609
GameObject [ ] selectedGOs = Selection . GetFiltered < GameObject > ( SelectionMode . TopLevel ) ;
3587
3610
string filename = null ;
@@ -3610,6 +3633,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3610
3633
/// Export a list of (Game) objects to FBX file.
3611
3634
/// Use the SaveFile panel to allow user to enter a file name.
3612
3635
/// <summary>
3636
+ //public static string ExportObjects (string filePath, UnityEngine.Object[] objects = null, AnimationExportType exportType = AnimationExportType.all /*, bool animOnly = false*/)
3613
3637
public static string ExportObjects (
3614
3638
string filePath ,
3615
3639
UnityEngine . Object [ ] objects = null ,
@@ -3666,6 +3690,7 @@ public static string ExportObjects (
3666
3690
return null ;
3667
3691
}
3668
3692
3693
+ //public static string ExportObject (string filePath, UnityEngine.Object root, AnimationExportType exportType = AnimationExportType.all /*, bool animOnly = false*/)
3669
3694
public static string ExportObject (
3670
3695
string filePath , UnityEngine . Object root ,
3671
3696
AnimationExportType exportType = AnimationExportType . all ,
0 commit comments