1
1
using System . IO ;
2
2
using System . Collections . Generic ;
3
3
using UnityEngine ;
4
- using UnityEngine . SceneManagement ;
5
4
using UnityEditor ;
6
5
using Unity . FbxSdk ;
7
6
using System . Linq ;
@@ -58,6 +57,8 @@ public static void Dump (this AnimationCurve animCurve, string message, float[]
58
57
namespace Editor
59
58
{
60
59
using CustomExtensions ;
60
+ using UnityEngine . Playables ;
61
+ using UnityEngine . Timeline ;
61
62
62
63
public class ModelExporter : System . IDisposable
63
64
{
@@ -79,6 +80,8 @@ public class ModelExporter : System.IDisposable
79
80
// from being passed to command, thus resulting in OnContextItem()
80
81
// being called only once regardless of what is selected.
81
82
const string MenuItemName = "GameObject/Export Model..." ;
83
+
84
+ const string ClipMenuItemName = "GameObject/Export All Recorded Animation Clips..." ;
82
85
83
86
const string FileBaseName = "Untitled" ;
84
87
@@ -2606,6 +2609,119 @@ private void ReplaceFile ()
2606
2609
}
2607
2610
}
2608
2611
2612
+ /// <summary>
2613
+ /// Add an option "Update from FBX" in the contextual GameObject menu.
2614
+ /// </summary>
2615
+ [ MenuItem ( ClipMenuItemName , false , 31 ) ]
2616
+ static void OnClipContextClick ( MenuCommand command )
2617
+ {
2618
+ /*var obs = Selection.objects;
2619
+ foreach (var obj in obs)
2620
+ {
2621
+ if (obj.GetType().Name.Contains("EditorClip"))
2622
+ {
2623
+ Debug.Log("clip selected");
2624
+ var selClip = obj.GetType().GetProperty("clip").GetValue(obj, null);
2625
+ var timeLineClip = selClip as UnityEngine.Timeline.TimelineClip;
2626
+ Debug.Log("clip name: " + timeLineClip.displayName);
2627
+ }
2628
+ }*/
2629
+
2630
+ // Now that we know we have stuff to export, get the user-desired path.
2631
+ string directory = string . IsNullOrEmpty ( LastFilePath )
2632
+ ? Application . dataPath
2633
+ : System . IO . Path . GetDirectoryName ( LastFilePath ) ;
2634
+
2635
+
2636
+ string title = string . Format ( "Export Model FBX ({0})" , FileBaseName ) ;
2637
+
2638
+ string folderPath = EditorUtility . SaveFolderPanel ( title , directory , "" ) ;
2639
+
2640
+ if ( string . IsNullOrEmpty ( folderPath ) )
2641
+ {
2642
+ return ;
2643
+ }
2644
+ Debug . Log ( folderPath ) ;
2645
+
2646
+ Object [ ] selection = null ;
2647
+
2648
+ if ( command == null || command . context == null )
2649
+ {
2650
+ // We were actually invoked from the top GameObject menu, so use the selection.
2651
+ selection = Selection . GetFiltered < Object > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
2652
+ }
2653
+ else
2654
+ {
2655
+ // We were invoked from the right-click menu, so use the context of the context menu.
2656
+ var selected = command . context as GameObject ;
2657
+ if ( selected )
2658
+ {
2659
+ selection = new GameObject [ ] { selected } ;
2660
+ }
2661
+ }
2662
+ foreach ( GameObject obj in selection )
2663
+ {
2664
+ Debug . Log ( obj . GetType ( ) . BaseType . ToString ( ) + ":" + obj . name ) ;
2665
+
2666
+ PlayableDirector pd = obj . GetComponent < PlayableDirector > ( ) ;
2667
+ if ( pd != null )
2668
+ {
2669
+ foreach ( PlayableBinding output in pd . playableAsset . outputs )
2670
+ {
2671
+ AnimationTrack at = output . sourceObject as AnimationTrack ;
2672
+
2673
+ GameObject atObject = pd . GetGenericBinding ( output . sourceObject ) as GameObject ;
2674
+
2675
+ //Debug.Log(pd.GetGenericBinding(output.sourceObject).name);
2676
+
2677
+ // var at = pd.GetGenericBinding(output.sourceObject) as GameObject;
2678
+ foreach ( TimelineClip myclip in at . GetClips ( ) )
2679
+ {
2680
+
2681
+ AnimationClip animationClip = myclip . animationClip ;
2682
+
2683
+ Debug . Log ( "output.streamName: " + output . streamName + " /Animation Track name: " + at . name + " : " + animationClip . name + " /myclip.displayName: " + myclip . displayName + " atObject.name " + atObject . name ) ;
2684
+
2685
+ Dictionary < GameObject , List < AnimationClip > > dict = new Dictionary < GameObject , List < AnimationClip > > ( ) ;
2686
+ // Detect if it's a recorded anim clip
2687
+ //ExportAnimationClip(animationClip, obj, null);
2688
+
2689
+
2690
+ // Export it to FBX in the path specified by the user.
2691
+ }
2692
+ }
2693
+ }
2694
+ }
2695
+
2696
+ }
2697
+
2698
+
2699
+ /// <summary>
2700
+ /// Validate the menu item defined by the function above.
2701
+ /// </summary>
2702
+ [ MenuItem ( ClipMenuItemName , true , 31 ) ]
2703
+ public static bool ValidateClipContextClick ( )
2704
+ {
2705
+ //return true;
2706
+
2707
+ Object [ ] selection = Selection . objects ;
2708
+
2709
+ if ( selection == null || selection . Length == 0 )
2710
+ {
2711
+ return false ;
2712
+ }
2713
+
2714
+ foreach ( GameObject obj in selection )
2715
+ {
2716
+ if ( obj . GetComponent < PlayableDirector > ( ) != null )
2717
+ {
2718
+ return true ;
2719
+ }
2720
+ }
2721
+
2722
+ return false ;
2723
+ }
2724
+
2609
2725
/// <summary>
2610
2726
/// Add a menu item to a GameObject's context menu.
2611
2727
/// </summary>
@@ -3198,4 +3314,4 @@ public static string ConvertToValidFilename(string filename)
3198
3314
}
3199
3315
}
3200
3316
}
3201
- }
3317
+ }
0 commit comments