Skip to content

Commit 88ad62c

Browse files
author
Benoit Hudson
committed
Rename ConvertToBlahBlahBlah with just one object to simply 'Convert'.
This is for Karl's probuilder benefit -- he's using reflection, and was picking up the wrong override. Also mucked a bit with the control flow of the version with arrays, which had subtly different handling depending on which menu we were coming from. Now we get the same call to the underlying API either way.
1 parent eaca519 commit 88ad62c

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ public static class ConvertToModel
2626
[MenuItem (MenuItemName1, false, 30)]
2727
static void OnContextItem (MenuCommand command)
2828
{
29+
GameObject [] selection = null;
30+
2931
if (command == null || command.context == null) {
30-
// We were actually invoked from the top GameObject menu,
31-
// not the context menu, so treat it as such.
32-
GameObject [] unityGameObjectsToConvert = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
33-
if (unityGameObjectsToConvert.Length <= 0) {
34-
ModelExporter.DisplayNoSelectionDialog ();
35-
return;
32+
// We were actually invoked from the top GameObject menu, so use the selection.
33+
selection = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
34+
} else {
35+
// We were invoked from the right-click menu, so use the context of the context menu.
36+
var selected = command.context as GameObject;
37+
if (selected) {
38+
selection = new GameObject[] { selected };
3639
}
37-
Object[] result = CreateInstantiatedModelPrefab (unityGameObjectsToConvert);
38-
if (result.Length>0)
39-
Selection.objects = result;
40-
return;
4140
}
4241

43-
GameObject selected = command.context as GameObject;
44-
if (selected == null) {
45-
Debug.LogError (string.Format("Error: {0} is not a GameObject and cannot be converted", command.context.name));
42+
if (selection == null || selection.Length == 0) {
43+
ModelExporter.DisplayNoSelectionDialog ();
4644
return;
4745
}
48-
GameObject[] result1 = CreateInstantiatedModelPrefab (new GameObject[]{selected});
49-
if (result1.Length>0)
50-
Selection.objects = result1;
5146

47+
try {
48+
Selection.objects = CreateInstantiatedModelPrefab (selection);
49+
} catch (System.Exception xcp) {
50+
Debug.LogException (xcp);
51+
}
5252
}
5353

5454
/// <summary>
@@ -83,7 +83,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
8383
var wasExported = new List<GameObject>();
8484
foreach(var go in toExport) {
8585
try {
86-
wasExported.Add(CreateInstantiatedModelPrefab(go,
86+
wasExported.Add(Convert(go,
8787
directoryFullPath: directoryFullPath,
8888
keepOriginal: keepOriginal));
8989
} catch(System.Exception xcp) {
@@ -112,7 +112,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
112112
/// fbxFullPath is specified. May be null, in which case we use the
113113
/// export settings.</param>
114114
/// <param name="keepOriginal">If set to <c>true</c>, keep the original in the scene.</param>
115-
public static GameObject CreateInstantiatedModelPrefab (
115+
public static GameObject Convert (
116116
GameObject toConvert,
117117
string directoryFullPath = null,
118118
string fbxFullPath = null,

Assets/FbxExporters/Editor/UnitTests/ConvertToModelTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void BasicTest()
133133
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
134134

135135
// Convert it to a prefab.
136-
var cubePrefabInstance = ConvertToModel.CreateInstantiatedModelPrefab(cube,
136+
var cubePrefabInstance = ConvertToModel.Convert(cube,
137137
directoryFullPath: path, keepOriginal: true);
138138

139139
// Make sure it's what we expect.

Assets/FbxExporters/Editor/UnitTests/FbxPrefabTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void TestCubeAtRoot()
351351
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
352352
cube.name = "Cube";
353353
var cubeAssetPath = GetRandomFbxFilePath();
354-
var autoPrefab = FbxExporters.Editor.ConvertToModel.CreateInstantiatedModelPrefab(cube,
354+
var autoPrefab = FbxExporters.Editor.ConvertToModel.Convert(cube,
355355
fbxFullPath: cubeAssetPath);
356356
Assert.IsTrue(autoPrefab);
357357

0 commit comments

Comments
 (0)