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