@@ -2661,6 +2661,36 @@ public void ComputeObjectsInAnimationClips(
2661
2661
}
2662
2662
}
2663
2663
2664
+ internal static GameObject GetGameObjectBoundToEditorClip ( object editorClip )
2665
+ {
2666
+ object clipItem = editorClip . GetType ( ) . GetProperty ( "item" ) . GetValue ( editorClip , null ) ;
2667
+ object parentTrack = clipItem . GetType ( ) . GetProperty ( "parentTrack" ) . GetValue ( clipItem , null ) ;
2668
+ AnimationTrack animTrack = parentTrack as AnimationTrack ;
2669
+
2670
+ #if UNITY_2018_2_OR_NEWER
2671
+ Object animationTrackObject = UnityEditor . Timeline . TimelineEditor . inspectedDirector . GetGenericBinding ( animTrack ) ;
2672
+ #else // UNITY_2018_2_OR_NEWER
2673
+ Object animationTrackObject = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( animTrack ) ;
2674
+ #endif // UNITY_2018_2_OR_NEWER
2675
+
2676
+ GameObject animationTrackGO = null ;
2677
+ if ( animationTrackObject is GameObject )
2678
+ {
2679
+ animationTrackGO = animationTrackObject as GameObject ;
2680
+ }
2681
+ else if ( animationTrackObject is Animator )
2682
+ {
2683
+ animationTrackGO = ( animationTrackObject as Animator ) . gameObject ;
2684
+ }
2685
+
2686
+ if ( animationTrackGO == null )
2687
+ {
2688
+ Debug . LogErrorFormat ( "Could not export animation track object of type {0}" , animationTrackObject . GetType ( ) . Name ) ;
2689
+ return null ;
2690
+ }
2691
+ return animationTrackGO ;
2692
+ }
2693
+
2664
2694
public static KeyValuePair < GameObject , AnimationClip > GetGameObjectAndAnimationClip ( Object obj )
2665
2695
{
2666
2696
if ( ! obj . GetType ( ) . Name . Contains ( "EditorClip" ) )
@@ -2669,13 +2699,13 @@ public static KeyValuePair<GameObject, AnimationClip> GetGameObjectAndAnimationC
2669
2699
object clip = obj . GetType ( ) . GetProperty ( "clip" ) . GetValue ( obj , null ) ;
2670
2700
TimelineClip timeLineClip = clip as TimelineClip ;
2671
2701
2672
- object clipItem = obj . GetType ( ) . GetProperty ( "item" ) . GetValue ( obj , null ) ;
2673
- object parentTrack = clipItem . GetType ( ) . GetProperty ( "parentTrack" ) . GetValue ( clipItem , null ) ;
2674
- AnimationTrack animTrack = parentTrack as AnimationTrack ;
2675
-
2676
- var goBound = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( animTrack ) as GameObject ;
2702
+ var animationTrackGO = GetGameObjectBoundToEditorClip ( obj ) ;
2703
+ if ( animationTrackGO == null )
2704
+ {
2705
+ return new KeyValuePair < GameObject , AnimationClip > ( ) ;
2706
+ }
2677
2707
2678
- return new KeyValuePair < GameObject , AnimationClip > ( goBound , timeLineClip . animationClip ) ;
2708
+ return new KeyValuePair < GameObject , AnimationClip > ( animationTrackGO , timeLineClip . animationClip ) ;
2679
2709
}
2680
2710
2681
2711
public static string GetFileName ( Object obj )
@@ -2691,12 +2721,11 @@ public static string GetFileName(Object obj)
2691
2721
}
2692
2722
else
2693
2723
{
2694
- object clipItem = obj . GetType ( ) . GetProperty ( "item" ) . GetValue ( obj , null ) ;
2695
- object parentTrack = clipItem . GetType ( ) . GetProperty ( "parentTrack" ) . GetValue ( clipItem , null ) ;
2696
- AnimationTrack animTrack = parentTrack as AnimationTrack ;
2697
-
2698
- var goBound = UnityEditor . Timeline . TimelineEditor . playableDirector . GetGenericBinding ( animTrack ) as GameObject ;
2699
-
2724
+ var goBound = GetGameObjectBoundToEditorClip ( obj ) ;
2725
+ if ( goBound == null )
2726
+ {
2727
+ return null ;
2728
+ }
2700
2729
return string . Format ( "{0}@{1}" , goBound . name , timeLineClip . displayName ) ;
2701
2730
}
2702
2731
}
@@ -3033,7 +3062,7 @@ internal int GetAnimOnlyHierarchyCount(Dictionary<GameObject, IExportData> hiera
3033
3062
return completeExpSet . Count ;
3034
3063
}
3035
3064
3036
- internal Dictionary < GameObject , IExportData > GetExportData ( Object [ ] objects , IExportOptions exportOptions = null )
3065
+ internal static Dictionary < GameObject , IExportData > GetExportData ( Object [ ] objects , IExportOptions exportOptions = null )
3037
3066
{
3038
3067
ExportSettings . Include includeOptions = ( exportOptions != null ) ? exportOptions . ModelAnimIncludeOption : ExportSettings . Include . ModelAndAnim ;
3039
3068
0 commit comments