44using System . Reflection ;
55using System . Linq ;
66using UnityEditor . ProBuilder ;
7+ using UnityEditor . ProBuilder . Actions ;
78
89namespace UnityEngine . ProBuilder . Addons . FBX
910{
@@ -40,13 +41,6 @@ private static Assembly FbxExporterAssembly
4041 }
4142 }
4243 }
43-
44- static readonly Type [ ] k_ProBuilderTypes = new Type [ ]
45- {
46- typeof ( BezierShape ) ,
47- typeof ( PolyShape ) ,
48- typeof ( Entity )
49- } ;
5044
5145 static FbxOptions m_FbxOptions = new FbxOptions ( ) {
5246 quads = true
@@ -71,12 +65,12 @@ static void TryLoadFbxSupport()
7165 var getMeshForComponent = FbxExporterAssembly . GetTypes ( )
7266 . Where ( t => t . BaseType == typeof ( MulticastDelegate ) && t . Name . StartsWith ( "GetMeshForComponent" ) )
7367 . First ( t => t . ContainsGenericParameters ) ;
74-
68+
7569 getMeshForComponent = getMeshForComponent . MakeGenericType ( typeof ( ProBuilderMesh ) ) ;
7670 var meshDelegate = Delegate . CreateDelegate ( getMeshForComponent , typeof ( Fbx ) . GetMethod ( "GetMeshForComponent" , BindingFlags . NonPublic | BindingFlags . Static ) ) ;
7771
7872 registerMeshCallback . Invoke ( null , new object [ ] { meshDelegate , true } ) ;
79-
73+
8074 m_FbxOptions . quads = ProBuilderSettings . Get < bool > ( "Export::m_FbxQuads" , SettingsScope . User , true ) ;
8175 }
8276
@@ -93,17 +87,17 @@ static bool GetMeshForComponent(object exporter, ProBuilderMesh pmesh, object no
9387
9488 Object . DestroyImmediate ( mesh ) ;
9589
96- // probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
97- foreach ( var type in k_ProBuilderTypes )
90+ var exporterType = exporter . GetType ( ) . GetMethods ( BindingFlags . NonPublic | BindingFlags . Instance )
91+ . First ( x => x . Name == "get_ExportOptions" ) . Invoke ( exporter , null ) . GetType ( ) ;
92+
93+ var prefabExporterType = FbxExporterAssembly . GetType ( "UnityEditor.Formats.Fbx.Exporter.ConvertToPrefabSettingsSerialize" ) ;
94+
95+ if ( exporterType == prefabExporterType )
9896 {
99- var component = pmesh . GetComponent ( type ) ;
100- if ( component != null )
101- Object . DestroyImmediate ( component ) ;
97+ // probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
98+ StripProBuilderScripts . DoStrip ( pmesh ) ;
10299 }
103100
104- pmesh . preserveMeshAssetOnDestroy = true ;
105- Object . DestroyImmediate ( pmesh ) ;
106-
107101 return true ;
108102 }
109103 }
0 commit comments