@@ -26,29 +26,29 @@ public static class ConvertToModel
26
26
[ MenuItem ( MenuItemName1 , false , 30 ) ]
27
27
static void OnContextItem ( MenuCommand command )
28
28
{
29
+ GameObject [ ] selection = null ;
30
+
29
31
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 } ;
36
39
}
37
- Object [ ] result = CreateInstantiatedModelPrefab ( unityGameObjectsToConvert ) ;
38
- if ( result . Length > 0 )
39
- Selection . objects = result ;
40
- return ;
41
40
}
42
41
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 ( ) ;
46
44
return ;
47
45
}
48
- GameObject [ ] result1 = CreateInstantiatedModelPrefab ( new GameObject [ ] { selected } ) ;
49
- if ( result1 . Length > 0 )
50
- Selection . objects = result1 ;
51
46
47
+ try {
48
+ Selection . objects = CreateInstantiatedModelPrefab ( selection ) ;
49
+ } catch ( System . Exception xcp ) {
50
+ Debug . LogException ( xcp ) ;
51
+ }
52
52
}
53
53
54
54
/// <summary>
@@ -83,7 +83,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
83
83
var wasExported = new List < GameObject > ( ) ;
84
84
foreach ( var go in toExport ) {
85
85
try {
86
- wasExported . Add ( CreateInstantiatedModelPrefab ( go ,
86
+ wasExported . Add ( Convert ( go ,
87
87
directoryFullPath : directoryFullPath ,
88
88
keepOriginal : keepOriginal ) ) ;
89
89
} catch ( System . Exception xcp ) {
@@ -112,7 +112,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
112
112
/// fbxFullPath is specified. May be null, in which case we use the
113
113
/// export settings.</param>
114
114
/// <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 (
116
116
GameObject toConvert ,
117
117
string directoryFullPath = null ,
118
118
string fbxFullPath = null ,
0 commit comments