Skip to content

Commit f384fed

Browse files
committed
clean up code so it's easier to read
1 parent c38a703 commit f384fed

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -291,29 +291,34 @@ private static void CopyComponents(GameObject from, GameObject to){
291291
var toComponent = originalComponents [j];
292292
// If component already exists, paste values.
293293
if (toComponent.GetType () == components [i].GetType ()) {
294+
// we have found the component we are looking for, remove it so
295+
// we don't try to copy to it again
296+
originalComponents.RemoveAt (j);
297+
foundComponentOfType = true;
298+
294299
// Don't want to copy MeshFilter because then we will replace the
295300
// exported mesh with the old mesh.
296-
if (!(toComponent is MeshFilter)) {
297-
// Don't want to copy materials over in case the materials are
298-
// embedded in another model.
299-
if (toComponent is SkinnedMeshRenderer) {
300-
var skinnedMesh = toComponent as SkinnedMeshRenderer;
301-
var sharedMesh = skinnedMesh.sharedMesh;
302-
var sharedMats = skinnedMesh.sharedMaterials;
303-
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
304-
skinnedMesh.sharedMesh = sharedMesh;
305-
skinnedMesh.sharedMaterials = sharedMats;
306-
} else if (toComponent is Renderer) {
307-
var renderer = toComponent as Renderer;
308-
var sharedMats = renderer.sharedMaterials;
309-
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
310-
renderer.sharedMaterials = sharedMats;
311-
} else {
312-
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
313-
}
301+
if (toComponent is MeshFilter) {
302+
break;
303+
}
304+
305+
// Don't want to copy materials over in case the materials are
306+
// embedded in another model.
307+
if (toComponent is SkinnedMeshRenderer) {
308+
var skinnedMesh = toComponent as SkinnedMeshRenderer;
309+
var sharedMesh = skinnedMesh.sharedMesh;
310+
var sharedMats = skinnedMesh.sharedMaterials;
311+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
312+
skinnedMesh.sharedMesh = sharedMesh;
313+
skinnedMesh.sharedMaterials = sharedMats;
314+
} else if (toComponent is Renderer) {
315+
var renderer = toComponent as Renderer;
316+
var sharedMats = renderer.sharedMaterials;
317+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
318+
renderer.sharedMaterials = sharedMats;
319+
} else {
320+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
314321
}
315-
originalComponents.RemoveAt (j);
316-
foundComponentOfType = true;
317322
break;
318323
}
319324
}

0 commit comments

Comments
 (0)