@@ -57,22 +57,16 @@ 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 ) ;
60
+ var exportSet = ModelExporter . RemoveRedundantObjects ( unityActiveGOs ) ;
61
61
GameObject [ ] gosToExport = new GameObject [ exportSet . Count ] ;
62
62
exportSet . CopyTo ( gosToExport ) ;
63
63
64
64
// find common ancestor root & filePath;
65
65
string [ ] filePaths = new string [ gosToExport . Length ] ;
66
66
string dirPath = Path . Combine ( Application . dataPath , "Objects" ) ;
67
67
68
- Transform [ ] unityCommonAncestors = new Transform [ gosToExport . Length ] ;
69
- int [ ] siblingIndices = new int [ gosToExport . Length ] ;
70
-
71
68
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" ) ;
69
+ filePaths [ n ] = Path . Combine ( dirPath , gosToExport [ n ] . name + ".fbx" ) ;
76
70
}
77
71
78
72
string [ ] fbxFileNames = new string [ filePaths . Length ] ;
@@ -110,28 +104,23 @@ private static List<GameObject> OnConvertInPlace ()
110
104
{
111
105
GameObject unityGO = unityObj as GameObject ;
112
106
Transform unityGOTransform = unityGO . transform ;
107
+ Transform origGOTransform = gosToExport [ i ] . transform ;
113
108
114
109
// Set the name to be the name of the instantiated asset.
115
110
// This will get rid of the "(Clone)" if it's added
116
111
unityGO . name = unityMainAsset . name ;
117
112
118
113
// configure transform and maintain local pose
119
- unityGO . transform . SetParent ( unityCommonAncestors [ i ] , false ) ;
114
+ unityGOTransform . SetParent ( origGOTransform . parent , false ) ;
120
115
121
- unityGO . transform . SetSiblingIndex ( siblingIndices [ i ] ) ;
116
+ unityGOTransform . SetSiblingIndex ( origGOTransform . GetSiblingIndex ( ) ) ;
122
117
123
118
// copy the components over, assuming that the hierarchy order is unchanged
124
- if ( unityActiveGOs . Length == 1 ) {
125
- CopyComponentsRecursive ( unityActiveGOs [ 0 ] , unityGO ) ;
126
- } else {
127
- if ( unityActiveGOs . Length != unityGOTransform . childCount ) {
128
- Debug . LogWarning ( string . Format ( "Warning: Exported {0} objects, but only imported {1}" ,
129
- unityActiveGOs . Length , unityGOTransform . childCount ) ) ;
130
- }
131
- for ( int i = 0 , c = unityGOTransform . childCount ; i < c ; i ++ ) {
132
- CopyComponentsRecursive ( unityActiveGOs [ i ] , unityGOTransform . GetChild ( i ) . gameObject ) ;
133
- }
119
+ if ( origGOTransform . hierarchyCount != unityGOTransform . hierarchyCount ) {
120
+ Debug . LogWarning ( string . Format ( "Warning: Exported {0} objects, but only imported {1}" ,
121
+ origGOTransform . hierarchyCount , unityGOTransform . hierarchyCount ) ) ;
134
122
}
123
+ CopyComponentsRecursive ( gosToExport [ i ] , unityGO ) ;
135
124
136
125
result . Add ( unityObj as GameObject ) ;
137
126
0 commit comments