Skip to content

Commit 3f62a00

Browse files
committed
move export + add to scene functions to exporter test base
1 parent 2de6434 commit 3f62a00

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,33 @@ protected virtual string ExportSelectedObjects(string filename, params Object[]
240240
return fbxFileName;
241241
}
242242

243+
/// <summary>
244+
/// Exports a single hierarchy to a random fbx file.
245+
/// </summary>
246+
/// <returns>The exported fbx file path.</returns>
247+
/// <param name="hierarchy">Hierarchy.</param>
248+
/// <param name="animOnly">If set to <c>true</c> export animation only.</param>
249+
protected string ExportToFbx (GameObject hierarchy, bool animOnly = false){
250+
string filename = GetRandomFbxFilePath ();
251+
var exportedFilePath = FbxExporters.Editor.ModelExporter.ExportObject (filename, hierarchy, animOnly);
252+
Assert.That (exportedFilePath, Is.EqualTo (filename));
253+
return filename;
254+
}
255+
256+
/// <summary>
257+
/// Adds the asset at asset path to the scene.
258+
/// </summary>
259+
/// <returns>The new GameObject in the scene.</returns>
260+
/// <param name="assetPath">Asset path.</param>
261+
protected GameObject AddAssetToScene(string assetPath){
262+
GameObject originalObj = AssetDatabase.LoadMainAssetAtPath ("Assets/" + assetPath) as GameObject;
263+
Assert.IsNotNull (originalObj);
264+
GameObject originalGO = GameObject.Instantiate (originalObj);
265+
Assert.IsTrue (originalGO);
266+
267+
return originalGO;
268+
}
269+
243270
/// <summary>
244271
/// Compares two hierarchies, asserts that they match precisely.
245272
/// The root can be allowed to mismatch. That's normal with

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,7 @@ public void LegacySkinnedMeshAnimTest (string fbxPath)
682682

683683
// export fbx
684684
// get GameObject
685-
string filename = GetRandomFbxFilePath ();
686-
ExportToFbx(filename, originalGO);
685+
string filename = ExportToFbx(originalGO);
687686

688687
// TODO: Uni-34492 change importer settings of (newly exported model)
689688
// so that it's not resampled and it is legacy animation
@@ -835,8 +834,7 @@ public void AnimOnlyExportTest(string prefabPath)
835834

836835
// export fbx
837836
// get GameObject
838-
string filename = GetRandomFbxFilePath ();
839-
ExportToFbx(filename, originalGO, true);
837+
string filename = ExportToFbx(originalGO, true);
840838

841839
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
842840
Assert.IsTrue (fbxObj);
@@ -864,11 +862,6 @@ public void AnimOnlyExportTest(string prefabPath)
864862
AnimTester.MultiClipTest (animClips, fbxAnimClips);
865863
}
866864

867-
public static void ExportToFbx (string filename, GameObject hierarchy, bool animOnly = false){
868-
var exportedFilePath = ModelExporter.ExportObject (filename, hierarchy, animOnly);
869-
Assert.That (exportedFilePath, Is.EqualTo (filename));
870-
}
871-
872865
public static AnimationClip[] GetClipsFromAnimator(Animator animator){
873866
Assert.That (animator, Is.Not.Null);
874867

@@ -881,15 +874,6 @@ public static AnimationClip[] GetClipsFromAnimator(Animator animator){
881874
return animClips;
882875
}
883876

884-
public static GameObject AddAssetToScene(string assetPath){
885-
GameObject originalObj = AssetDatabase.LoadMainAssetAtPath ("Assets/" + assetPath) as GameObject;
886-
Assert.IsNotNull (originalObj);
887-
GameObject originalGO = GameObject.Instantiate (originalObj);
888-
Assert.IsTrue (originalGO);
889-
890-
return originalGO;
891-
}
892-
893877
private HashSet<string> GetAnimatedGameObjects(AnimationClip[] animClips, GameObject animatorObject){
894878
var animatedObjects = new HashSet<string>();
895879
foreach (var clip in animClips) {

Assets/FbxExporters/Editor/UnitTests/RotationCurveTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@ public void TestBasics() {
4040
}
4141

4242
[Test, TestCaseSource (typeof (AnimationTestDataClass), "RotationCurveTestCases")]
43-
public void TestCurveExport (string prefabPath) {
43+
public void TestEulerCurveExport (string prefabPath) {
4444
prefabPath = FindPathInUnitTests (prefabPath);
4545
Assert.That (prefabPath, Is.Not.Null);
4646

4747
// add fbx to scene
48-
GameObject originalGO = FbxAnimationTest.AddAssetToScene(prefabPath);
48+
GameObject originalGO = AddAssetToScene(prefabPath);
4949

5050
// get clips
5151
var animator = originalGO.GetComponentInChildren<Animator> ();
5252
var animClips = FbxAnimationTest.GetClipsFromAnimator (animator);
5353

5454
// export fbx
55-
string filename = GetRandomFbxFilePath ();
56-
FbxAnimationTest.ExportToFbx(filename, originalGO);
55+
string filename = ExportToFbx(originalGO);
5756

5857
var fbxAnimClips = FbxAnimationTest.AnimTester.GetClipsFromFbx (filename);
5958

0 commit comments

Comments
 (0)