@@ -92,7 +92,7 @@ public static string MaterialToString(Material material) {
9292 }
9393
9494 public class ZOExportOBJ : EditorWindow {
95- public bool _exportSubMeshes = false ;
95+ public bool _exportSubMeshes = true ;
9696 public bool _zeroPosition = true ;
9797 private string _selectedNames ;
9898
@@ -142,7 +142,6 @@ public static void DoExport(bool makeSubmeshes, string fileDirectory, bool zeroP
142142 }
143143
144144 string meshName = gameObject . name ;
145- // string fileName = EditorUtility.SaveFilePanel("Export .obj file", "", meshName, "obj");
146145
147146 ZOObjExporter . Start ( ) ;
148147
@@ -187,6 +186,15 @@ public static void DoExport(bool makeSubmeshes, string fileDirectory, bool zeroP
187186 string materialString = ZOObjExporter . MaterialToString ( material ) ;
188187 mtlFileString . Append ( materialString ) ;
189188 materialNames . Add ( material . name ) ;
189+
190+ // handle texture
191+ if ( material . HasProperty ( "_MainTex" ) ) {
192+ string assetPath = AssetDatabase . GetAssetPath ( material . GetTexture ( "_MainTex" ) ) ;
193+ if ( string . IsNullOrEmpty ( assetPath ) == false ) {
194+ string texName = Path . GetFileName ( assetPath ) ;
195+ File . Copy ( assetPath , Path . Combine ( fileDirectory , texName ) ) ;
196+ }
197+ }
190198 }
191199 }
192200 }
@@ -205,6 +213,14 @@ public static void DoExport(bool makeSubmeshes, string fileDirectory, bool zeroP
205213 string materialString = ZOObjExporter . MaterialToString ( material ) ;
206214 mtlFileString . Append ( materialString ) ;
207215 materialNames . Add ( material . name ) ;
216+ // handle texture
217+ if ( material . HasProperty ( "_MainTex" ) ) {
218+ string assetPath = AssetDatabase . GetAssetPath ( material . GetTexture ( "_MainTex" ) ) ;
219+ if ( string . IsNullOrEmpty ( assetPath ) == false ) {
220+ string texName = Path . GetFileName ( assetPath ) ;
221+ File . Copy ( assetPath , Path . Combine ( fileDirectory , texName ) ) ;
222+ }
223+ }
208224 }
209225 }
210226 }
0 commit comments