Skip to content

Commit 0eed55a

Browse files
committed
fix compile errors and warnings
- reuse code to get the object bound to the editor clip
1 parent e604eec commit 0eed55a

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,6 +2661,36 @@ public void ComputeObjectsInAnimationClips(
26612661
}
26622662
}
26632663

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+
26642694
public static KeyValuePair<GameObject, AnimationClip> GetGameObjectAndAnimationClip(Object obj)
26652695
{
26662696
if (!obj.GetType().Name.Contains("EditorClip"))
@@ -2669,13 +2699,13 @@ public static KeyValuePair<GameObject, AnimationClip> GetGameObjectAndAnimationC
26692699
object clip = obj.GetType().GetProperty("clip").GetValue(obj, null);
26702700
TimelineClip timeLineClip = clip as TimelineClip;
26712701

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+
}
26772707

2678-
return new KeyValuePair<GameObject, AnimationClip>(goBound, timeLineClip.animationClip);
2708+
return new KeyValuePair<GameObject, AnimationClip>(animationTrackGO, timeLineClip.animationClip);
26792709
}
26802710

26812711
public static string GetFileName(Object obj)
@@ -2691,12 +2721,11 @@ public static string GetFileName(Object obj)
26912721
}
26922722
else
26932723
{
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+
}
27002729
return string.Format ("{0}@{1}", goBound.name, timeLineClip.displayName);
27012730
}
27022731
}
@@ -3033,7 +3062,7 @@ internal int GetAnimOnlyHierarchyCount(Dictionary<GameObject, IExportData> hiera
30333062
return completeExpSet.Count;
30343063
}
30353064

3036-
internal Dictionary<GameObject, IExportData> GetExportData(Object[] objects, IExportOptions exportOptions = null)
3065+
internal static Dictionary<GameObject, IExportData> GetExportData(Object[] objects, IExportOptions exportOptions = null)
30373066
{
30383067
ExportSettings.Include includeOptions = (exportOptions!=null) ? exportOptions.ModelAnimIncludeOption : ExportSettings.Include.ModelAndAnim;
30393068

0 commit comments

Comments
 (0)