Skip to content

Commit eb62260

Browse files
committed
Code review fixes
- remove sorting code that doesn't really work for general case - performance improvements - make sure we don't try to copy deleted components
1 parent 1164336 commit eb62260

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ private static List<GameObject> OnConvertInPlace ()
5757

5858
GameObject [] unityActiveGOs = Selection.GetFiltered<GameObject> (SelectionMode.Editable | SelectionMode.TopLevel);
5959

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-
6560
// find common ancestor root & filePath;
6661
string filePath = "";
6762
string dirPath = Path.Combine (Application.dataPath, "Objects");
@@ -99,6 +94,7 @@ private static List<GameObject> OnConvertInPlace ()
9994
if (unityObj != null)
10095
{
10196
GameObject unityGO = unityObj as GameObject;
97+
Transform unityGOTransform = unityGO.transform;
10298

10399
// configure name
104100
const string cloneSuffix = "(Clone)";
@@ -109,21 +105,21 @@ private static List<GameObject> OnConvertInPlace ()
109105

110106
// configure transform and maintain local pose
111107
if (unityCommonAncestor != null) {
112-
unityGO.transform.SetParent (unityCommonAncestor.transform, false);
108+
unityGOTransform.SetParent (unityCommonAncestor.transform, false);
113109
}
114110

115-
unityGO.transform.SetSiblingIndex (siblingIndex);
111+
unityGOTransform.SetSiblingIndex (siblingIndex);
116112

117113
// copy the components over, assuming that the hierarchy order is unchanged
118114
if (unityActiveGOs.Length == 1) {
119115
CopyComponentsRecursive (unityActiveGOs [0], unityGO);
120116
} else {
121-
if (unityActiveGOs.Length != unityGO.transform.childCount) {
117+
if (unityActiveGOs.Length != unityGOTransform.childCount) {
122118
Debug.LogWarning (string.Format ("Warning: Exported {0} objects, but only imported {1}",
123-
unityActiveGOs.Length, unityGO.transform.childCount));
119+
unityActiveGOs.Length, unityGOTransform.childCount));
124120
}
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);
127123
}
128124
}
129125

@@ -167,7 +163,7 @@ private static void CopyComponents(GameObject from, GameObject to){
167163
var components = from.GetComponents<Component> ();
168164
for(int i = 0; i < components.Length; i++){
169165
// 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){
171167
continue;
172168
}
173169
bool success = UnityEditorInternal.ComponentUtility.CopyComponent (components[i]);

0 commit comments

Comments
 (0)