Skip to content

Commit 8693c9d

Browse files
committed
add light unit test
1 parent 4cc1341 commit 8693c9d

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,24 @@ public void TestExportCamera(){
361361
/// <param name="filename">Filename.</param>
362362
/// <param name="cameraObj">Camera object.</param>
363363
private Camera ExportCamera(string filename, GameObject cameraObj){
364-
ModelExporter.ExportObject (filename, cameraObj);
364+
ExportComponent<Camera> (filename, cameraObj);
365+
}
366+
367+
/// <summary>
368+
/// Exports the GameObject and returns component of type T.
369+
/// </summary>
370+
/// <returns>The component.</returns>
371+
/// <param name="filename">Filename.</param>
372+
/// <param name="obj">Object.</param>
373+
/// <typeparam name="T">The component type.</typeparam>
374+
private T ExportComponent<T>(string filename, GameObject obj) where T : Component {
375+
ModelExporter.ExportObject (filename, obj);
365376

366377
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath(filename) as GameObject;
367-
var fbxCamera = fbxObj.GetComponent<Camera> ();
378+
var fbxComponent = fbxObj.GetComponent<T> ();
368379

369-
Assert.IsNotNull (fbxCamera);
370-
return fbxCamera;
380+
Assert.IsNotNull (fbxComponent);
381+
return fbxComponent;
371382
}
372383

373384
private void CompareCameraValues(Camera camera, Camera fbxCamera, float delta=0.001f){
@@ -376,5 +387,35 @@ private void CompareCameraValues(Camera camera, Camera fbxCamera, float delta=0.
376387
Assert.AreEqual (camera.nearClipPlane, fbxCamera.nearClipPlane, delta);
377388
Assert.AreEqual (camera.farClipPlane, fbxCamera.farClipPlane, delta);
378389
}
390+
391+
[Test]
392+
public void TestExportLight()
393+
{
394+
// create a Unity light
395+
GameObject lightObj = new GameObject("TestLight");
396+
Light light = lightObj.AddComponent<Light> ();
397+
398+
light.type = LightType.Spot;
399+
light.spotAngle = 55.4f;
400+
light.color = Color.blue;
401+
light.intensity = 2.3f;
402+
light.range = 45;
403+
light.shadows = LightShadows.Soft;
404+
405+
string filename = GetRandomFbxFilePath ();
406+
var fbxLight = ExportComponent<Light> (filename, lightObj);
407+
CompareLightValues (light, fbxLight);
408+
}
409+
410+
private void CompareLightValues(Light light, Light fbxLight, float delta=0.001f){
411+
Assert.AreEqual (light.type, fbxLight.type);
412+
if (light.type == LightType.Spot) {
413+
Assert.AreEqual (light.spotAngle, fbxLight.spotAngle, delta);
414+
}
415+
Assert.AreEqual (light.color, fbxLight.color);
416+
Assert.AreEqual (light.intensity, fbxLight.intensity, delta);
417+
Assert.AreEqual (light.range, fbxLight.range, delta);
418+
// compare shadows
419+
}
379420
}
380421
}

0 commit comments

Comments
 (0)