@@ -149,6 +149,14 @@ public void ReplaceTest ()
149
149
150
150
public class FbxPrefabAutoUpdaterRemappingTest : ExporterTestBase
151
151
{
152
+ bool isAutoUpdaterOn ;
153
+ [ SetUp ]
154
+ public void Init ( )
155
+ {
156
+ isAutoUpdaterOn = FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled ;
157
+ FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled = true ;
158
+ }
159
+
152
160
[ Test ]
153
161
public void RemappingTest ( )
154
162
{
@@ -194,6 +202,77 @@ public void RemappingTest()
194
202
Assert . IsTrue ( cubePrefabInstance . transform . GetChild ( 0 ) . name == "SphereFBX" ) ;
195
203
Assert . IsTrue ( cubePrefabInstance . transform . GetChild ( 0 ) . GetComponent < MeshFilter > ( ) . sharedMesh != null ) ;
196
204
}
205
+ [ TearDown ]
206
+ public void stopTest ( )
207
+ {
208
+ FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled = isAutoUpdaterOn ;
209
+ }
210
+ }
211
+
212
+ public class FbxPrefabAutoUpdaterToggleTest : ExporterTestBase
213
+ {
214
+ bool isAutoUpdaterOn ;
215
+ [ SetUp ]
216
+ public void Init ( )
217
+ {
218
+ isAutoUpdaterOn = FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled ;
219
+ FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled = false ;
220
+ }
221
+
222
+ [ Test ]
223
+ public void RemappingTest ( )
224
+ {
225
+ //Create a hierarchy of objects
226
+ GameObject cube = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
227
+ GameObject sphere = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
228
+ sphere . transform . SetParent ( cube . transform ) ;
229
+ GameObject cylinder = GameObject . CreatePrimitive ( PrimitiveType . Cylinder ) ;
230
+ cylinder . transform . SetParent ( sphere . transform ) ;
231
+
232
+ string filePath = GetRandomFbxFilePath ( ) ;
233
+
234
+ // Convert to linked prefab instance (auto-updating prefab)
235
+ GameObject cubePrefabInstance = ConvertToModel . Convert ( cube , fbxFullPath : filePath ) ;
236
+ Object cubePrefabParent = PrefabUtility . GetPrefabParent ( cubePrefabInstance ) ;
237
+
238
+ // In FbxPrefab Component of Cube, add SphereFBX/Sphere name mapping
239
+ FbxPrefab fbxPrefabScript = cubePrefabInstance . transform . GetComponent < FbxPrefab > ( ) ;
240
+ FbxPrefab . StringPair stringpair = new FbxPrefab . StringPair ( ) ;
241
+ stringpair . FBXObjectName = "SphereFBX" ;
242
+ stringpair . UnityObjectName = "Sphere" ;
243
+ fbxPrefabScript . NameMapping . Add ( stringpair ) ;
244
+ PrefabUtility . ReplacePrefab ( cubePrefabInstance , cubePrefabParent ) ;
245
+
246
+
247
+ //Create second FBX
248
+ GameObject cube2 = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
249
+ GameObject sphere2 = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
250
+ // Change name of Sphere to SphereFBX
251
+ sphere2 . transform . name = "SphereFBX" ;
252
+ sphere2 . transform . SetParent ( cube2 . transform ) ;
253
+ GameObject cylinder2 = GameObject . CreatePrimitive ( PrimitiveType . Cylinder ) ;
254
+ cylinder2 . transform . SetParent ( sphere2 . transform ) ;
255
+
256
+
257
+ //export our updated hierarchy to the same file path as the original
258
+ SleepForFileTimestamp ( ) ;
259
+ // "Import" model to Unity (Exporting modified FBX to Unity to see if the remapping works)
260
+ ExportSelectedObjects ( filePath , cube2 ) ;
261
+ AssetDatabase . Refresh ( ) ;
262
+
263
+ // Assert Check Sphere = Sphere and has been changed by the Auto-Updater.
264
+ Assert . IsTrue ( cubePrefabInstance != null ) ;
265
+ Assert . IsTrue ( cubePrefabInstance . GetComponent < MeshFilter > ( ) . sharedMesh != null ) ;
266
+ Assert . IsTrue ( cubePrefabInstance . transform . GetChild ( 0 ) . name == "Sphere" ) ;
267
+ Assert . IsTrue ( cubePrefabInstance . transform . GetChild ( 0 ) . GetComponent < MeshFilter > ( ) . sharedMesh != null ) ;
268
+ }
269
+
270
+
271
+ [ TearDown ]
272
+ public void stopTest ( )
273
+ {
274
+ FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled = isAutoUpdaterOn ;
275
+ }
197
276
}
198
277
}
199
278
0 commit comments