Skip to content

Commit 329cfd3

Browse files
authored
Merge pull request #25 from Unity-Technologies/UNI-21304-fix-dup-safe-to-delete
UNI-21304 Fix duplated safe to delete objects
2 parents d2984de + 8b60cd0 commit 329cfd3

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public void Dispose () { }
3232
[MenuItem (MenuItemName1, false)]
3333
public static void OnMenuItem ()
3434
{
35-
OnConvertInPlace ();
35+
GameObject [] unityActiveGOs = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
36+
OnConvertInPlace (unityActiveGOs);
3637
}
3738

3839
/// <summary>
@@ -45,18 +46,27 @@ public static bool OnValidateMenuItem ()
4546
}
4647

4748
// Add a menu item called "Export Model..." to a GameObject's context menu.
49+
// OnContextItem gets called once per selected object
50+
// (if the parent and child are selected, then OnContextItem will only be called on the parent)
4851
[MenuItem (MenuItemName2, false, 30)]
4952
static void OnContextItem (MenuCommand command)
5053
{
51-
OnConvertInPlace ();
54+
if (command == null || command.context == null) {
55+
Debug.LogError ("Error: No GameObject selected");
56+
return;
57+
}
58+
GameObject selected = command.context as GameObject;
59+
if (selected == null) {
60+
Debug.LogError (string.Format("Error: {0} is not a GameObject and cannot be converted", command.context.name));
61+
return;
62+
}
63+
OnConvertInPlace (new GameObject[]{selected});
5264
}
5365

54-
private static List<GameObject> OnConvertInPlace ()
66+
private static List<GameObject> OnConvertInPlace (GameObject [] unityActiveGOs)
5567
{
5668
List<GameObject> result = new List<GameObject> ();
5769

58-
GameObject [] unityActiveGOs = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
59-
6070
var exportSet = ModelExporter.RemoveRedundantObjects (unityActiveGOs);
6171
GameObject[] gosToExport = new GameObject[exportSet.Count];
6272
exportSet.CopyTo (gosToExport);

0 commit comments

Comments
 (0)