@@ -57,11 +57,6 @@ private static List<GameObject> OnConvertInPlace ()
57
57
58
58
GameObject [ ] unityActiveGOs = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
59
59
60
- // Ensure that the root GameObjects retain their relative order after export
61
- System . Array . Sort ( unityActiveGOs , delegate ( GameObject x , GameObject y ) {
62
- return x . transform . GetSiblingIndex ( ) . CompareTo ( y . transform . GetSiblingIndex ( ) ) ;
63
- } ) ;
64
-
65
60
// find common ancestor root & filePath;
66
61
string filePath = "" ;
67
62
string dirPath = Path . Combine ( Application . dataPath , "Objects" ) ;
@@ -99,6 +94,7 @@ private static List<GameObject> OnConvertInPlace ()
99
94
if ( unityObj != null )
100
95
{
101
96
GameObject unityGO = unityObj as GameObject ;
97
+ Transform unityGOTransform = unityGO . transform ;
102
98
103
99
// configure name
104
100
const string cloneSuffix = "(Clone)" ;
@@ -109,21 +105,21 @@ private static List<GameObject> OnConvertInPlace ()
109
105
110
106
// configure transform and maintain local pose
111
107
if ( unityCommonAncestor != null ) {
112
- unityGO . transform . SetParent ( unityCommonAncestor . transform , false ) ;
108
+ unityGOTransform . SetParent ( unityCommonAncestor . transform , false ) ;
113
109
}
114
110
115
- unityGO . transform . SetSiblingIndex ( siblingIndex ) ;
111
+ unityGOTransform . SetSiblingIndex ( siblingIndex ) ;
116
112
117
113
// copy the components over, assuming that the hierarchy order is unchanged
118
114
if ( unityActiveGOs . Length == 1 ) {
119
115
CopyComponentsRecursive ( unityActiveGOs [ 0 ] , unityGO ) ;
120
116
} else {
121
- if ( unityActiveGOs . Length != unityGO . transform . childCount ) {
117
+ if ( unityActiveGOs . Length != unityGOTransform . childCount ) {
122
118
Debug . LogWarning ( string . Format ( "Warning: Exported {0} objects, but only imported {1}" ,
123
- unityActiveGOs . Length , unityGO . transform . childCount ) ) ;
119
+ unityActiveGOs . Length , unityGOTransform . childCount ) ) ;
124
120
}
125
- for ( int i = 0 ; i < unityGO . transform . childCount ; i ++ ) {
126
- CopyComponentsRecursive ( unityActiveGOs [ i ] , unityGO . transform . GetChild ( i ) . gameObject ) ;
121
+ for ( int i = 0 , c = unityGOTransform . childCount ; i < c ; i ++ ) {
122
+ CopyComponentsRecursive ( unityActiveGOs [ i ] , unityGOTransform . GetChild ( i ) . gameObject ) ;
127
123
}
128
124
}
129
125
@@ -167,7 +163,7 @@ private static void CopyComponents(GameObject from, GameObject to){
167
163
var components = from . GetComponents < Component > ( ) ;
168
164
for ( int i = 0 ; i < components . Length ; i ++ ) {
169
165
// if to already has this component, then skip it
170
- if ( to . GetComponent ( components [ i ] . GetType ( ) ) != null ) {
166
+ if ( components [ i ] == null || to . GetComponent ( components [ i ] . GetType ( ) ) != null ) {
171
167
continue ;
172
168
}
173
169
bool success = UnityEditorInternal . ComponentUtility . CopyComponent ( components [ i ] ) ;
0 commit comments