Skip to content

Commit 6ef435a

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into UNI-20471-write-to-temp-file-when-exporting
# Conflicts: # Assets/FbxExporters/Editor/FbxExporter.cs
2 parents ad8d5ef + e93813a commit 6ef435a

File tree

5 files changed

+421
-142
lines changed

5 files changed

+421
-142
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,31 @@ private static void CopyComponents(GameObject from, GameObject to){
287287
if (success) {
288288
// if to already has this component, then copy the values over
289289
var toComponent = to.GetComponent (components [i].GetType ());
290-
if (toComponent != null) {
291-
// don't want to copy MeshFilter because then we will replace the
292-
// exported mesh with the old mesh
293-
if (!(toComponent is MeshFilter)) {
294-
if (toComponent is SkinnedMeshRenderer) {
295-
var skinnedMesh = toComponent as SkinnedMeshRenderer;
296-
var sharedMesh = skinnedMesh.sharedMesh;
297-
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
298-
skinnedMesh.sharedMesh = sharedMesh;
299-
} else {
300-
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
301-
}
302-
}
303-
} else {
290+
if (toComponent == null) {
304291
success = UnityEditorInternal.ComponentUtility.PasteComponentAsNew (to);
292+
} else{
293+
// Don't want to copy MeshFilter because then we will replace the
294+
// exported mesh with the old mesh.
295+
if (toComponent is MeshFilter) {
296+
continue;
297+
}
298+
// Don't want to copy materials over either in case the materials are
299+
// embedded in another model.
300+
else if (toComponent is SkinnedMeshRenderer) {
301+
var skinnedMesh = toComponent as SkinnedMeshRenderer;
302+
var sharedMesh = skinnedMesh.sharedMesh;
303+
var sharedMats = skinnedMesh.sharedMaterials;
304+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
305+
skinnedMesh.sharedMesh = sharedMesh;
306+
skinnedMesh.sharedMaterials = sharedMats;
307+
} else if (toComponent is Renderer) {
308+
var renderer = toComponent as Renderer;
309+
var sharedMats = renderer.sharedMaterials;
310+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
311+
renderer.sharedMaterials = sharedMats;
312+
} else {
313+
success = UnityEditorInternal.ComponentUtility.PasteComponentValues (toComponent);
314+
}
305315
}
306316
}
307317
if (!success) {

0 commit comments

Comments
 (0)