Skip to content

Commit 5a9a823

Browse files
committed
Pull Request changes
1 parent dac4e27 commit 5a9a823

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
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: 8 additions & 3 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?
@@ -182,7 +188,7 @@ public string GetUnityObjectName(string fbxObjectName)
182188
public string GetFBXObjectName(string unityObjectName)
183189
{
184190
string oldNameInFBX = unityObjectName;
185-
if (unityObjectName != "" && m_fbxPrefab.NameMapping != null) {
191+
if (String.IsNullOrEmpty(unityObjectName) && m_fbxPrefab.NameMapping != null) {
186192
foreach (var nameMapping in m_fbxPrefab.NameMapping) {
187193
if (unityObjectName == nameMapping.UnityObjectName) {
188194
oldNameInFBX = nameMapping.FBXObjectName;
@@ -455,7 +461,6 @@ void InitFromJson(string json, ref int index)
455461
string name = ReadString(json, ref index);
456462
Consume(':', json, ref index);
457463

458-
459464
// hack: If the name starts with a '-' it's the name
460465
// of a gameobject, and we parse it recursively. Otherwise
461466
// it's the name of a component, and we store its value as a string.
@@ -1036,7 +1041,7 @@ public HashSet<GameObject> ImplementUpdates(FbxPrefab prefabInstance)
10361041
foreach(var componentType in typesToDestroy) {
10371042
var component = prefabXfo.GetComponent(componentType);
10381043
if (component != null) {
1039-
Object.DestroyImmediate(component);
1044+
GameObject.DestroyImmediate(component);
10401045
Log("destroyed component {0}:{1}", nodeName, componentType);
10411046
}
10421047
}

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,16 @@ protected virtual GameObject ExportSelection(params Object[] selected)
235235

236236
protected virtual string ExportSelectedObjects(string filename, params Object[] selected)
237237
{
238-
var fbxFileName = FbxExporters.Editor.ModelExporter.ExportObjects(filename, selected) as string;
238+
string fbxFileName = FbxExporters.Editor.ModelExporter.ExportObjects(filename, selected);
239239

240240
return fbxFileName;
241241
}
242242

243-
244-
245-
/// <summary>
246-
/// Compares two hierarchies, asserts that they match precisely.
247-
/// The root can be allowed to mismatch. That's normal with
248-
/// GameObject.Instantiate.
249-
/// </summary>
243+
/// <summary>
244+
/// Compares two hierarchies, asserts that they match precisely.
245+
/// The root can be allowed to mismatch. That's normal with
246+
/// GameObject.Instantiate.
247+
/// </summary>
250248
public static void AssertSameHierarchy (
251249
GameObject expectedHierarchy, GameObject actualHierarchy,
252250
bool ignoreRootName = false, bool ignoreRootTransform = false)

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ public void RemappingTest()
159159
GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
160160
cylinder.transform.SetParent(sphere.transform);
161161

162+
string filePath = GetRandomFbxFilePath();
163+
162164
// Convert to linked prefab instance (auto-updating prefab)
163-
GameObject cubePrefabInstance = ConvertToModel.Convert(cube);
165+
GameObject cubePrefabInstance = ConvertToModel.Convert(cube, fbxFullPath: filePath);
164166
Object cubePrefabParent = PrefabUtility.GetPrefabParent(cubePrefabInstance);
165167

166168
// In FbxPrefab Component of Cube, add SphereFBX/Sphere name mapping
@@ -184,18 +186,14 @@ public void RemappingTest()
184186
//export our updated hierarchy to the same file path as the original
185187
SleepForFileTimestamp();
186188
// "Import" model to Unity (Exporting modified FBX to Unity to see if the remapping works)
187-
string fbxFileName = ExportSelectedObjects(Application.dataPath + "/Cube.fbx", cube2);
189+
string fbxFileName = ExportSelectedObjects(filePath, cube2);
188190
AssetDatabase.Refresh();
189191

190192
// Assert Check Sphere = SphereFBX
191193
Assert.IsTrue(cubePrefabInstance != null);
192194
Assert.IsTrue(cubePrefabInstance.GetComponent<MeshFilter>().sharedMesh != null);
193195
Assert.IsTrue(cubePrefabInstance.transform.GetChild(0).name == "SphereFBX");
194196
Assert.IsTrue(cubePrefabInstance.transform.GetChild(0).GetComponent<MeshFilter>().sharedMesh != null);
195-
196-
// Destroy the objects
197-
GameObject.DestroyImmediate(cubePrefabInstance);
198-
//GameObject.DestroyImmediate(cube2);
199197
}
200198
}
201199
}

0 commit comments

Comments
 (0)