@@ -57,25 +57,36 @@ private static List<GameObject> OnConvertInPlace ()
57
57
58
58
GameObject [ ] unityActiveGOs = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
59
59
60
+ var exportSet = ModelExporter . RemoveDuplicateObjects ( unityActiveGOs ) ;
61
+ GameObject [ ] gosToExport = new GameObject [ exportSet . Count ] ;
62
+ exportSet . CopyTo ( gosToExport ) ;
63
+
60
64
// find common ancestor root & filePath;
61
- string filePath = "" ;
65
+ string [ ] filePaths = new string [ gosToExport . Length ] ;
62
66
string dirPath = Path . Combine ( Application . dataPath , "Objects" ) ;
63
67
64
- GameObject unityCommonAncestor = null ;
65
- int siblingIndex = - 1 ;
66
-
67
- foreach ( GameObject goObj in unityActiveGOs ) {
68
- siblingIndex = goObj . transform . GetSiblingIndex ( ) ;
69
- unityCommonAncestor = ( goObj . transform . parent != null ) ? goObj . transform . parent . gameObject : null ;
70
- filePath = Path . Combine ( dirPath , goObj . name + ".fbx" ) ;
68
+ Transform [ ] unityCommonAncestors = new Transform [ gosToExport . Length ] ;
69
+ int [ ] siblingIndices = new int [ gosToExport . Length ] ;
71
70
72
- break ;
71
+ for ( int n = 0 ; n < gosToExport . Length ; n ++ ) {
72
+ GameObject goObj = gosToExport [ n ] ;
73
+ unityCommonAncestors [ n ] = goObj . transform . parent ;
74
+ siblingIndices [ n ] = goObj . transform . GetSiblingIndex ( ) ;
75
+ filePaths [ n ] = Path . Combine ( dirPath , goObj . name + ".fbx" ) ;
73
76
}
74
77
75
- string fbxFileName = FbxExporters . Editor . ModelExporter . ExportObjects ( filePath , unityActiveGOs ) as string ;
78
+ string [ ] fbxFileNames = new string [ filePaths . Length ] ;
76
79
77
- if ( fbxFileName != null )
80
+ for ( int j = 0 ; j < gosToExport . Length ; j ++ ) {
81
+ fbxFileNames [ j ] = FbxExporters . Editor . ModelExporter . ExportObjects ( filePaths [ j ] ,
82
+ new UnityEngine . Object [ ] { gosToExport [ j ] } ) as string ;
83
+ }
84
+
85
+ List < GameObject > selection = new List < GameObject > ( ) ;
86
+ for ( int i = 0 ; i < fbxFileNames . Length ; i ++ )
78
87
{
88
+ var fbxFileName = fbxFileNames [ i ] ;
89
+
79
90
// make filepath relative to project folder
80
91
if ( fbxFileName . StartsWith ( Application . dataPath , System . StringComparison . CurrentCulture ) )
81
92
{
@@ -103,33 +114,30 @@ private static List<GameObject> OnConvertInPlace ()
103
114
}
104
115
105
116
// configure transform and maintain local pose
106
- if ( unityCommonAncestor != null ) {
107
- unityGO . transform . SetParent ( unityCommonAncestor . transform , false ) ;
108
- }
117
+ unityGO . transform . SetParent ( unityCommonAncestors [ i ] , false ) ;
109
118
110
- unityGO . transform . SetSiblingIndex ( siblingIndex ) ;
119
+ unityGO . transform . SetSiblingIndex ( siblingIndices [ i ] ) ;
111
120
112
121
result . Add ( unityObj as GameObject ) ;
113
122
114
- // remove (now redundant) gameobjects
115
- for ( int i = 0 ; i < unityActiveGOs . Length ; i ++ ) {
123
+ // remove (now redundant) gameobject
116
124
#if UNI_19965
117
- Object . DestroyImmediate ( unityActiveGOs [ i ] ) ;
125
+ Object . DestroyImmediate ( unityActiveGOs [ i ] ) ;
118
126
#else
119
- // rename and put under scene root in case we need to check values
120
- unityActiveGOs [ i ] . name = "_safe_to_delete_" + unityActiveGOs [ i ] . name ;
121
- unityActiveGOs [ i ] . transform . parent = null ;
122
- unityActiveGOs [ i ] . SetActive ( false ) ;
127
+ // rename and put under scene root in case we need to check values
128
+ gosToExport [ i ] . name = "_safe_to_delete_" + gosToExport [ i ] . name ;
129
+ gosToExport [ i ] . transform . parent = null ;
130
+ gosToExport [ i ] . SetActive ( false ) ;
123
131
#endif
124
- }
125
-
126
132
// select the instanced Model Prefab
127
- Selection . objects = new GameObject [ ] { unityGO } ;
133
+ selection . Add ( unityGO ) ;
128
134
}
129
135
}
130
136
131
137
}
132
138
139
+ Selection . objects = selection . ToArray ( ) ;
140
+
133
141
return result ;
134
142
}
135
143
}
0 commit comments