@@ -434,6 +434,44 @@ public void TestTransformAndReparenting()
434
434
Assert . That ( original . transform . GetChild ( 0 ) . GetChild ( 0 ) . name , Is . EqualTo ( "building3" ) ) ;
435
435
Assert . That ( original . transform . GetChild ( 0 ) . GetChild ( 0 ) . localScale , Is . EqualTo ( new Vector3 ( .5f , .5f , .5f ) ) ) ;
436
436
}
437
+
438
+ [ Test ]
439
+ public void TestFbxPrefabNotAtRoot ( )
440
+ {
441
+ // UNI-23143: what happens if you have an FbxPrefab that's not at the root of its prefab?
442
+ // Use case: table and chair are two separate fbx files, but we
443
+ // combine them into one prefab.
444
+
445
+ // Create a cube fbx/prefab pair.
446
+ var cube = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
447
+ var cubeMesh = cube . GetComponent < MeshFilter > ( ) . sharedMesh ;
448
+ var cubePath = GetRandomFbxFilePath ( ) ;
449
+ var cubeInstance = ConvertToModel . Convert ( cube , fbxFullPath : cubePath ) ;
450
+ var cubeName = cubeInstance . name ;
451
+
452
+ // Create a prefab that has the cube as a child.
453
+ // Test the test: make sure the structure is what we expect.
454
+ var root = new GameObject ( "root" ) ;
455
+ cubeInstance . transform . parent = root . transform ;
456
+ var rootPrefab = PrefabUtility . CreatePrefab ( GetRandomPrefabAssetPath ( ) , root ) ;
457
+ Assert . That ( rootPrefab ) ;
458
+ Assert . That ( rootPrefab . GetComponent < MeshFilter > ( ) , Is . Null ) ;
459
+ Assert . That ( rootPrefab . transform . GetChild ( 0 ) . name == cubeName ) ;
460
+ Assert . AreEqual ( 24 , rootPrefab . transform . GetChild ( 0 ) . GetComponent < MeshFilter > ( ) . sharedMesh . vertexCount ) ;
461
+
462
+ // Turn the cube into a quad by exporting over its fbx file.
463
+ var quad = GameObject . CreatePrimitive ( PrimitiveType . Quad ) ;
464
+ var quadMesh = quad . GetComponent < MeshFilter > ( ) . sharedMesh ;
465
+ ModelExporter . ExportObject ( cubePath , quad ) ;
466
+
467
+ // The actual test:
468
+ // Make sure the rootPrefab has the structure we expect.
469
+ // Before fixing the bug, the root of the prefab was destroyed and recreated, so the very first test here failed:
470
+ Assert . That ( rootPrefab ) ;
471
+ Assert . That ( rootPrefab . GetComponent < MeshFilter > ( ) , Is . Null ) ;
472
+ Assert . That ( rootPrefab . transform . GetChild ( 0 ) . name == cubeName ) ;
473
+ Assert . AreEqual ( 4 , rootPrefab . transform . GetChild ( 0 ) . GetComponent < MeshFilter > ( ) . sharedMesh . vertexCount ) ;
474
+ }
437
475
}
438
476
439
477
public class FbxPrefabHelpersTest
0 commit comments