Skip to content

Commit f7659fe

Browse files
authored
Merge pull request #286 from Unity-Technologies/Uni-35933-disable-auto-update-branch
Uni 35933 disable auto update branch
2 parents 97ef6ca + 0698464 commit f7659fe

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public override void OnInspectorGUI() {
5050
exportSettings.centerObjects
5151
);
5252

53+
exportSettings.autoUpdaterEnabled = EditorGUILayout.Toggle(
54+
new GUIContent("Auto-Updater:",
55+
"Automatically updates prefabs with new fbx data that was imported."),
56+
exportSettings.autoUpdaterEnabled
57+
);
58+
5359
GUILayout.BeginHorizontal();
5460
EditorGUILayout.LabelField(new GUIContent("Export Format:", "Export the FBX file in the standard binary format." +
5561
" Select ASCII to export the FBX file in ASCII format."), GUILayout.Width(LabelWidth - FieldOffset));
@@ -424,6 +430,7 @@ public static string[] DCCVendorLocations
424430
// Note: default values are set in LoadDefaults().
425431
public bool mayaCompatibleNames = true;
426432
public bool centerObjects = true;
433+
public bool autoUpdaterEnabled = true;
427434
public bool launchAfterInstallation = true;
428435
public bool HideSendToUnityMenu = true;
429436
public int ExportFormatSelection;
@@ -456,6 +463,7 @@ protected override void LoadDefaults()
456463
{
457464
mayaCompatibleNames = true;
458465
centerObjects = true;
466+
autoUpdaterEnabled = true;
459467
launchAfterInstallation = true;
460468
HideSendToUnityMenu = true;
461469
ExportFormatSelection = 0;

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public static bool MayHaveFbxPrefabToFbxAsset(string prefabPath,
8181

8282
static void OnPostprocessAllAssets(string [] imported, string [] deleted, string [] moved, string [] movedFrom)
8383
{
84+
// Do not start if Auto Updater is disabled in FBX Exporter Settings
85+
if (!FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled)
86+
{
87+
return;
88+
}
89+
8490
//Debug.Log("Postprocessing...");
8591

8692
// Did we import an fbx file at all?

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ public void ReplaceTest ()
149149

150150
public class FbxPrefabAutoUpdaterRemappingTest : ExporterTestBase
151151
{
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+
152160
[Test]
153161
public void RemappingTest()
154162
{
@@ -194,6 +202,77 @@ public void RemappingTest()
194202
Assert.IsTrue(cubePrefabInstance.transform.GetChild(0).name == "SphereFBX");
195203
Assert.IsTrue(cubePrefabInstance.transform.GetChild(0).GetComponent<MeshFilter>().sharedMesh != null);
196204
}
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+
}
197276
}
198277
}
199278

0 commit comments

Comments
 (0)