@@ -103,26 +103,10 @@ private static List<GameObject> OnConvertInPlace ()
103
103
if ( unityObj != null )
104
104
{
105
105
GameObject unityGO = unityObj as GameObject ;
106
- Transform unityGOTransform = unityGO . transform ;
107
- Transform origGOTransform = gosToExport [ i ] . transform ;
108
106
109
- // Set the name to be the name of the instantiated asset.
110
- // This will get rid of the "(Clone)" if it's added
111
- unityGO . name = unityMainAsset . name ;
107
+ SetupImportedGameObject ( gosToExport [ i ] , unityGO ) ;
112
108
113
- // configure transform and maintain local pose
114
- unityGOTransform . SetParent ( origGOTransform . parent , false ) ;
115
-
116
- unityGOTransform . SetSiblingIndex ( origGOTransform . GetSiblingIndex ( ) ) ;
117
-
118
- // copy the components over, assuming that the hierarchy order is unchanged
119
- if ( origGOTransform . hierarchyCount != unityGOTransform . hierarchyCount ) {
120
- Debug . LogWarning ( string . Format ( "Warning: Exported {0} objects, but only imported {1}" ,
121
- origGOTransform . hierarchyCount , unityGOTransform . hierarchyCount ) ) ;
122
- }
123
- CopyComponentsRecursive ( gosToExport [ i ] , unityGO ) ;
124
-
125
- result . Add ( unityObj as GameObject ) ;
109
+ result . Add ( unityGO ) ;
126
110
127
111
// remove (now redundant) gameobject
128
112
#if UNI_19965
@@ -144,6 +128,37 @@ private static List<GameObject> OnConvertInPlace ()
144
128
return result ;
145
129
}
146
130
131
+ private static void SetupImportedGameObject ( GameObject orig , GameObject imported )
132
+ {
133
+ Transform importedTransform = imported . transform ;
134
+ Transform origTransform = orig . transform ;
135
+
136
+ // Set the name to be the name of the instantiated asset.
137
+ // This will get rid of the "(Clone)" if it's added
138
+ imported . name = orig . name ;
139
+
140
+ // configure transform and maintain local pose
141
+ importedTransform . SetParent ( origTransform . parent , false ) ;
142
+ importedTransform . SetSiblingIndex ( origTransform . GetSiblingIndex ( ) ) ;
143
+
144
+ // set the transform to be the same as before
145
+ bool success = UnityEditorInternal . ComponentUtility . CopyComponent ( origTransform ) ;
146
+ if ( success ) {
147
+ success = UnityEditorInternal . ComponentUtility . PasteComponentValues ( importedTransform ) ;
148
+ }
149
+ if ( ! success ) {
150
+ Debug . LogWarning ( string . Format ( "Warning: Failed to copy component Transform from {0} to {1}" ,
151
+ imported . name , origTransform . name ) ) ;
152
+ }
153
+
154
+ // copy the components over, assuming that the hierarchy order is unchanged
155
+ if ( origTransform . hierarchyCount != importedTransform . hierarchyCount ) {
156
+ Debug . LogWarning ( string . Format ( "Warning: Exported {0} objects, but only imported {1}" ,
157
+ origTransform . hierarchyCount , importedTransform . hierarchyCount ) ) ;
158
+ }
159
+ CopyComponentsRecursive ( orig , imported ) ;
160
+ }
161
+
147
162
private static void CopyComponentsRecursive ( GameObject from , GameObject to ) {
148
163
if ( ! to . name . StartsWith ( from . name ) || from . transform . childCount != to . transform . childCount ) {
149
164
Debug . LogError ( string . Format ( "Error: hierarchies don't match (From: {0}, To: {1})" , from . name , to . name ) ) ;
0 commit comments