Skip to content

Commit 52a5771

Browse files
authored
Merge pull request #272 from Unity-Technologies/UNI-35582-export-anim-after-components
UNI-35582 export animation after components
2 parents a9821f5 + 3711b14 commit 52a5771

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,8 @@ protected int ExportTransformHierarchy(
18991899
/// </summary>
19001900
protected bool ExportComponents(FbxScene fbxScene)
19011901
{
1902+
var animationNodes = new HashSet<GameObject> ();
1903+
19021904
int numObjectsExported = 0;
19031905
int objectCount = MapUnityObjectToFbxNode.Count;
19041906
foreach (KeyValuePair<GameObject, FbxNode> entry in MapUnityObjectToFbxNode) {
@@ -1932,13 +1934,35 @@ protected bool ExportComponents(FbxScene fbxScene)
19321934
ExportLight (unityGo, fbxScene, fbxNode);
19331935
}
19341936

1935-
// now (try) export animation
1936-
ExportAnimation (unityGo, fbxScene);
1937+
// check if this object contains animation, keep track of it
1938+
// if it does
1939+
if (GameObjectHasAnimation (unityGo)) {
1940+
animationNodes.Add (unityGo);
1941+
}
1942+
}
19371943

1944+
// export all GameObjects that have animation
1945+
if (animationNodes.Count > 0) {
1946+
foreach (var go in animationNodes) {
1947+
ExportAnimation (go, fbxScene);
1948+
}
19381949
}
1950+
19391951
return true;
19401952
}
19411953

1954+
/// <summary>
1955+
/// Checks if the GameObject has animation.
1956+
/// </summary>
1957+
/// <returns><c>true</c>, if object has animation, <c>false</c> otherwise.</returns>
1958+
/// <param name="go">Go.</param>
1959+
protected bool GameObjectHasAnimation(GameObject go){
1960+
return go != null &&
1961+
go.GetComponent<Animator> () ||
1962+
go.GetComponent<Animation> () ||
1963+
go.GetComponent<UnityEngine.Playables.PlayableDirector> ();
1964+
}
1965+
19421966
/// <summary>
19431967
/// A count of how many GameObjects we are exporting, to have a rough
19441968
/// idea of how long creating the scene will take.

0 commit comments

Comments
 (0)