3
3
using UnityEngine . TestTools ;
4
4
using NUnit . Framework ;
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
7
8
namespace FbxExporters . UnitTests
8
9
{
@@ -84,7 +85,7 @@ public static void AssertAreIdentical(
84
85
// Verify that they have the same children (by name).
85
86
var achildren = a . ChildNames ;
86
87
var bchildren = b . ChildNames ;
87
- Assert . That ( achildren , Is . EquivalentTo ( bchildren ) , aName + " children" ) ;
88
+ Assert . That ( bchildren , Is . EquivalentTo ( achildren ) , aName + " children" ) ;
88
89
89
90
// Add the children to each stack. It's important to get the
90
91
// same order for both stacks.
@@ -96,7 +97,8 @@ public static void AssertAreIdentical(
96
97
// Verify that they have the same components.
97
98
var atypes = a . ComponentTypes ;
98
99
var btypes = b . ComponentTypes ;
99
- Assert . That ( atypes , Is . EquivalentTo ( btypes ) , aName + " component types" ) ;
100
+
101
+ Assert . That ( btypes , Is . EquivalentTo ( atypes ) , aName + " component types" ) ;
100
102
101
103
foreach ( var t in atypes ) {
102
104
var avalues = a . GetComponentValues ( t ) ;
@@ -189,15 +191,14 @@ FbxPrefab.FbxRepresentation History(GameObject go) {
189
191
190
192
GameObject ModifySourceFbx ( )
191
193
{
192
- // Modify the source fbx file :
194
+ // Generate this change :
193
195
// - delete parent1
194
196
// - add parent3
195
- var newModel = PrefabUtility . InstantiatePrefab ( m_source ) as GameObject ;
197
+ // Simulate that we're doing this in Maya, so parent3 doesn't come
198
+ // with a collider.
199
+ var newModel = CreateHierarchy ( ) ;
196
200
GameObject . DestroyImmediate ( newModel . transform . Find ( "Parent1" ) . gameObject ) ;
197
201
var parent3 = CreateGameObject ( "Parent3" , newModel . transform ) ;
198
-
199
- // We're not doing an apply operation, so the collider isn't
200
- // supposed to get to the prefab, so don't test that it does.
201
202
Object . DestroyImmediate ( parent3 . GetComponent < BoxCollider > ( ) ) ;
202
203
203
204
// Export it to clobber the old FBX file.
@@ -235,25 +236,21 @@ public void BasicTest() {
235
236
// Make sure the fbx source changed (testing the test).
236
237
AssertAreDifferent ( m_originalHistory , Rep ( m_source ) ) ;
237
238
238
- // Make sure the auto-update prefab changed.
239
- Debug . Log ( string . Format ( "source: {0}\n prefab: {1}" ,
240
- newHierarchy . ToJson ( ) , Rep ( m_autoPrefab ) . ToJson ( ) ) ) ;
241
- AssertAreIdentical ( newHierarchy , Rep ( m_autoPrefab ) ) ;
242
- AssertAreIdentical ( newHierarchy , Rep ( m_source ) ) ;
243
-
244
- // Make sure the manual-update prefab didn't.
239
+ // Make sure the manual-update prefab didn't change.
245
240
AssertAreIdentical ( m_originalRep , Rep ( m_manualPrefab ) ) ;
246
241
AssertAreIdentical ( m_originalHistory , History ( m_manualPrefab ) ) ;
247
242
248
243
// Make sure we got the right changes.
249
244
Assert . AreEqual ( 1 , updateSet . NumUpdates ) ;
250
245
Assert . That ( updateSet . Updated , Is . EquivalentTo ( new string [ ] {
251
- // TODO: UNI-24579 - we should only be seeing Parent3 here,
252
- // the other two are for transform changes, but
253
- // they shouldn't have changed at all
254
- "Parent2" , "Parent3" , "Child3"
246
+ // TODO: UNI-24579 - we should only be seeing Parent3 here.
247
+ // Parent2 is for a transform change, but it shouldn't have changed.
248
+ "Parent2" , "Parent3"
255
249
}
256
250
) ) ;
251
+
252
+ // Make sure the auto-update prefab changed.
253
+ AssertAreIdentical ( newHierarchy , Rep ( m_autoPrefab ) ) ;
257
254
}
258
255
259
256
// Manual update, make sure it updated.
@@ -290,16 +287,27 @@ public void BasicTest() {
290
287
291
288
// Switch to some other model, which looks like the original model
292
289
// (but is a totally different file). This will cause an update
293
- // immediately. We expect to have lost the colliders on the objects
294
- // that were deleted in the interim.
290
+ // immediately.
295
291
var fbxAsset = FbxExporters . Editor . ModelExporter . ExportObject (
296
292
GetRandomFbxFilePath ( ) , m_original ) ;
297
293
var newSource = AssetDatabase . LoadMainAssetAtPath ( fbxAsset ) as GameObject ;
298
294
Assert . IsTrue ( newSource ) ;
299
295
Debug . Log ( "Testing SetSourceModel relink" ) ;
300
296
manualPrefabComponent . SetSourceModel ( newSource ) ;
301
- AssertAreIdentical ( m_originalRep , Rep ( m_manualPrefab ) ) ;
302
- AssertAreIdentical ( m_originalHistory , History ( m_manualPrefab ) ) ;
297
+
298
+ // Generate the answer we expect: the original but Parent1 and
299
+ // hierarchy are without collider. That's because we deleted them,
300
+ // and got them back.
301
+ var expectedHierarchy = GameObject . Instantiate ( m_original ) ;
302
+ var parent1 = expectedHierarchy . transform . Find ( "Parent1" ) ;
303
+ foreach ( var collider in parent1 . GetComponentsInChildren < BoxCollider > ( ) ) {
304
+ Object . DestroyImmediate ( collider ) ;
305
+ }
306
+ var expectedRep = Rep ( expectedHierarchy ) ;
307
+ var expectedHistory = m_originalHistory ;
308
+
309
+ AssertAreIdentical ( expectedHistory , History ( m_manualPrefab ) ) ;
310
+ AssertAreIdentical ( expectedRep , Rep ( m_manualPrefab ) ) ;
303
311
}
304
312
305
313
[ Test ]
0 commit comments