@@ -32,7 +32,8 @@ public void Dispose () { }
32
32
[ MenuItem ( MenuItemName1 , false ) ]
33
33
public static void OnMenuItem ( )
34
34
{
35
- OnConvertInPlace ( ) ;
35
+ GameObject [ ] unityActiveGOs = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
36
+ OnConvertInPlace ( unityActiveGOs ) ;
36
37
}
37
38
38
39
/// <summary>
@@ -45,18 +46,27 @@ public static bool OnValidateMenuItem ()
45
46
}
46
47
47
48
// 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)
48
51
[ MenuItem ( MenuItemName2 , false , 30 ) ]
49
52
static void OnContextItem ( MenuCommand command )
50
53
{
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 } ) ;
52
64
}
53
65
54
- private static List < GameObject > OnConvertInPlace ( )
66
+ private static List < GameObject > OnConvertInPlace ( GameObject [ ] unityActiveGOs )
55
67
{
56
68
List < GameObject > result = new List < GameObject > ( ) ;
57
69
58
- GameObject [ ] unityActiveGOs = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
59
-
60
70
var exportSet = ModelExporter . RemoveRedundantObjects ( unityActiveGOs ) ;
61
71
GameObject [ ] gosToExport = new GameObject [ exportSet . Count ] ;
62
72
exportSet . CopyTo ( gosToExport ) ;
0 commit comments