@@ -18,51 +18,30 @@ namespace Editor
18
18
{
19
19
public class ConvertToModel : System . IDisposable
20
20
{
21
- const string MenuItemName1 = "Assets/Convert To Prefab" ;
22
- const string MenuItemName2 = "GameObject/Convert To Prefab" ;
21
+ const string MenuItemName1 = "GameObject/Convert To Prefab" ;
23
22
24
23
/// <summary>
25
24
/// Clean up this class on garbage collection
26
25
/// </summary>
27
26
public void Dispose ( ) { }
28
27
29
- /// <summary>
30
- /// create menu item in the File menu
31
- /// </summary>
32
- [ MenuItem ( MenuItemName1 , false ) ]
33
- public static void OnMenuItem ( )
34
- {
35
- GameObject [ ] unityGameObjectsToConvert = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
36
- if ( unityGameObjectsToConvert . Length <= 0 ) {
37
- ModelExporter . DisplayNoSelectionDialog ( ) ;
38
- return ;
39
- }
40
-
41
- Object [ ] result = CreateInstantiatedModelPrefab ( unityGameObjectsToConvert ) ;
42
- if ( result . Length > 0 ) {
43
- Selection . objects = result ;
44
- }
45
- }
46
-
47
- /// <summary>
48
- // Validate the menu item defined by the function above.
49
- /// </summary>
50
- [ MenuItem ( MenuItemName1 , true ) ]
51
- public static bool OnValidateMenuItem ( )
52
- {
53
- return true ;
54
- }
55
-
56
28
// Add a menu item called "Export Model..." to a GameObject's context menu.
57
29
// OnContextItem gets called once per selected object
58
30
// (if the parent and child are selected, then OnContextItem will only be called on the parent)
59
- [ MenuItem ( MenuItemName2 , false , 30 ) ]
31
+ [ MenuItem ( MenuItemName1 , false , 30 ) ]
60
32
static void OnContextItem ( MenuCommand command )
61
33
{
62
34
if ( command == null || command . context == null ) {
63
35
// We were actually invoked from the top GameObject menu,
64
36
// not the context menu, so treat it as such.
65
- OnMenuItem ( ) ;
37
+ GameObject [ ] unityGameObjectsToConvert = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
38
+ if ( unityGameObjectsToConvert . Length <= 0 ) {
39
+ ModelExporter . DisplayNoSelectionDialog ( ) ;
40
+ return ;
41
+ }
42
+ Object [ ] result = CreateInstantiatedModelPrefab ( unityGameObjectsToConvert ) ;
43
+ if ( result . Length > 0 )
44
+ Selection . objects = result ;
66
45
return ;
67
46
}
68
47
@@ -71,10 +50,19 @@ static void OnContextItem (MenuCommand command)
71
50
Debug . LogError ( string . Format ( "Error: {0} is not a GameObject and cannot be converted" , command . context . name ) ) ;
72
51
return ;
73
52
}
74
- GameObject [ ] result = CreateInstantiatedModelPrefab ( new GameObject [ ] { selected } ) ;
75
- if ( result . Length > 0 )
76
- Selection . objects = result ;
53
+ GameObject [ ] result1 = CreateInstantiatedModelPrefab ( new GameObject [ ] { selected } ) ;
54
+ if ( result1 . Length > 0 )
55
+ Selection . objects = result1 ;
56
+
57
+ }
77
58
59
+ /// <summary>
60
+ // Validate the menu item defined by the function above.
61
+ /// </summary>
62
+ [ MenuItem ( MenuItemName1 , true , 30 ) ]
63
+ public static bool OnValidateMenuItem ( )
64
+ {
65
+ return true ;
78
66
}
79
67
80
68
/// <summary>
0 commit comments