@@ -386,5 +386,62 @@ public void TestStatics()
386
386
Assert . AreEqual ( quoted , FbxPrefab . FbxRepresentation . EscapeString ( unquoted ) ) ;
387
387
}
388
388
}
389
+
390
+ static void TestFbxRepresentationMatches ( FbxPrefab . FbxRepresentation repA )
391
+ {
392
+ // Look at the top of TestFbxRepresentation for the construction.
393
+
394
+ // The root doesn't have the fbxprefab or transform stored -- just the collider
395
+ Assert . That ( repA . ChildNames , Is . EquivalentTo ( new string [ ] { "b" } ) ) ;
396
+ Assert . That ( repA . ComponentTypes , Is . EquivalentTo ( new string [ ] { "UnityEngine.CapsuleCollider" } ) ) ;
397
+ Assert . IsNull ( repA . GetComponentValues ( "UnityEngine.Transform" ) ) ;
398
+ Assert . IsNull ( repA . GetComponentValues ( "UnityEngine.FbxPrefab" ) ) ;
399
+ Assert . AreEqual ( 1 , repA . GetComponentValues ( "UnityEngine.CapsuleCollider" ) . Count ) ;
400
+
401
+ // The child does have the transform.
402
+ var repB = repA . GetChild ( "b" ) ;
403
+ Assert . That ( repB . ChildNames , Is . EquivalentTo ( new string [ ] { } ) ) ;
404
+ Assert . That ( repB . ComponentTypes , Is . EquivalentTo ( new string [ ] {
405
+ "UnityEngine.Transform" ,
406
+ "UnityEngine.BoxCollider" } ) ) ;
407
+ Assert . AreEqual ( 1 , repB . GetComponentValues ( "UnityEngine.Transform" ) . Count ) ;
408
+ Assert . AreEqual ( 1 , repB . GetComponentValues ( "UnityEngine.BoxCollider" ) . Count ) ;
409
+
410
+ // The transform better have the right values.
411
+ var c = new GameObject ( "c" ) ;
412
+ EditorJsonUtility . FromJsonOverwrite (
413
+ repB . GetComponentValues ( "UnityEngine.Transform" ) [ 0 ] ,
414
+ c . transform ) ;
415
+ Assert . AreEqual ( new Vector3 ( 1 , 2 , 3 ) , c . transform . localPosition ) ;
416
+
417
+ // The capsule collider too.
418
+ var capsule = c . AddComponent < CapsuleCollider > ( ) ;
419
+ EditorJsonUtility . FromJsonOverwrite (
420
+ repA . GetComponentValues ( "UnityEngine.CapsuleCollider" ) [ 0 ] ,
421
+ capsule ) ;
422
+ Assert . AreEqual ( 4 , capsule . height ) ;
423
+ }
424
+
425
+ [ Test ]
426
+ public void TestFbxRepresentation ( )
427
+ {
428
+ var a = new GameObject ( "a" ) ;
429
+ a . AddComponent < FbxPrefab > ( ) ;
430
+ var acapsule = a . AddComponent < CapsuleCollider > ( ) ;
431
+ acapsule . height = 4 ;
432
+
433
+ var b = new GameObject ( "b" ) ;
434
+ b . transform . parent = a . transform ;
435
+ b . transform . localPosition = new Vector3 ( 1 , 2 , 3 ) ;
436
+ b . AddComponent < BoxCollider > ( ) ;
437
+
438
+ var repA = new FbxPrefab . FbxRepresentation ( a . transform ) ;
439
+ TestFbxRepresentationMatches ( repA ) ;
440
+
441
+ // Test that we can round-trip through a string.
442
+ var json = repA . ToJson ( ) ;
443
+ var repAstring = new FbxPrefab . FbxRepresentation ( json ) ;
444
+ TestFbxRepresentationMatches ( repAstring ) ;
445
+ }
389
446
}
390
447
}
0 commit comments