Skip to content

Commit f402eeb

Browse files
author
AJubrey
committed
[ADDED] unit test for autoupdating rectTransforms
1 parent c3775d9 commit f402eeb

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NUnit.Framework;
44
using System.IO;
55
using System.Collections.Generic;
6+
using FbxExporters.Editor;
67

78
namespace FbxExporters.UnitTests
89
{
@@ -57,6 +58,9 @@ public void BasicTest ()
5758
[Test]
5859
public void RectTransformTest ()
5960
{
61+
// Get a random directory.
62+
var path = m_fbxPath;
63+
6064
//Create a hierarchy with a RectTransform
6165
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
6266
var capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
@@ -67,16 +71,14 @@ public void RectTransformTest ()
6771

6872
capsule.transform.parent = cube.transform;
6973

70-
GameObject originalFBX = ExportSelection(cube);
74+
string filePath = Application.dataPath + "/cube.fbx";
7175

7276
//instantiate our hierarchy as a prefab
73-
var oldInstance = PrefabUtility.InstantiatePrefab(originalFBX) as GameObject;
77+
var oldInstance = ConvertToModel.Convert(cube, fbxFullPath: filePath);
7478
Assert.IsTrue(oldInstance);
7579

76-
Debug.Log("ORIGINAL: " + oldInstance.transform.GetChild(0).GetComponent<RectTransform>().localScale);
77-
78-
//Get the file path of our original hierarchy
79-
string filePath = AssetDatabase.GetAssetPath(originalFBX);
80+
Assert.AreEqual(oldInstance.transform.GetChild(0).GetComponent<RectTransform>().localScale, new Vector3(1, 2, 3));
81+
Assert.AreEqual(oldInstance.transform.GetChild(0).GetComponent<RectTransform>().localPosition, new Vector3(100, 200, 300));
8082

8183
//Create an "updated" hierarchy
8284
var cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
@@ -86,22 +88,18 @@ public void RectTransformTest ()
8688
capsule2.GetComponent<RectTransform>().localScale = new Vector3(3, 2, 1);
8789
capsule2.GetComponent<RectTransform>().localPosition = new Vector3(300, 200, 100);
8890

89-
capsule2.transform.parent = cube2.transform;
90-
91-
GameObject newFBX = ExportSelection(cube2);
91+
capsule2.transform.parent = cube2.transform;
9292

9393
//export our updated hierarchy to the same file path as the original
9494
SleepForFileTimestamp();
9595
FbxExporters.Editor.ModelExporter.ExportObject(filePath, cube2);
9696
AssetDatabase.Refresh();
9797

98-
var newInstance = PrefabUtility.InstantiatePrefab(newFBX) as GameObject;
99-
Assert.IsTrue(newInstance);
100-
101-
Debug.Log("NEW BOI: " + newInstance.transform.GetChild(0).GetComponent<RectTransform>().localScale);
102-
103-
AssertSameHierarchy(cube2, oldInstance, ignoreRootName: true, ignoreRootTransform: true);
98+
Assert.AreEqual(oldInstance.transform.GetChild(0).GetComponent<RectTransform>().localScale, new Vector3(3,2,1));
99+
Assert.AreEqual(oldInstance.transform.GetChild(0).GetComponent<RectTransform>().localPosition, new Vector3(300, 200, 100));
104100

101+
GameObject.DestroyImmediate(cube);
102+
GameObject.DestroyImmediate(cube2);
105103
}
106104

107105
[Test]

0 commit comments

Comments
 (0)