@@ -9,24 +9,25 @@ namespace FbxExporters
9
9
{
10
10
namespace Editor
11
11
{
12
- public class ExportModelEditorWindow : EditorWindow
12
+ public abstract class ExportOptionsEditorWindow : EditorWindow
13
13
{
14
+ protected const string DefaultWindowTitle = "Export Options" ;
15
+ protected const float SelectableLabelMinWidth = 90 ;
16
+ protected const float BrowseButtonWidth = 25 ;
17
+ protected const float LabelWidth = 175 ;
18
+ protected const float FieldOffset = 18 ;
19
+ protected const float TextFieldAlignOffset = 3 ;
20
+ protected const float ExportButtonWidth = 100 ;
21
+ protected const float FbxExtOffset = - 7 ;
14
22
15
- private const string WindowTitle = "Export Options" ;
16
- private const float SelectableLabelMinWidth = 90 ;
17
- private const float BrowseButtonWidth = 25 ;
18
- private const float LabelWidth = 175 ;
19
- private const float FieldOffset = 18 ;
20
- private const float TextFieldAlignOffset = 3 ;
21
- private const float ExportButtonWidth = 100 ;
22
- private const float FbxExtOffset = - 7 ;
23
+ protected virtual GUIContent m_windowTitle { get { return new GUIContent ( DefaultWindowTitle ) ; } }
23
24
24
- private string m_exportFileName = "" ;
25
- private ModelExporter . AnimationExportType m_animExportType = ModelExporter . AnimationExportType . all ;
26
- private bool m_singleHierarchyExport = true ;
25
+ protected string m_exportFileName = "" ;
26
+ protected ModelExporter . AnimationExportType m_animExportType = ModelExporter . AnimationExportType . all ;
27
+ protected bool m_singleHierarchyExport = true ;
27
28
28
- private ExportModelSettingsEditor m_innerEditor ;
29
- private static FbxExportPresetSelectorReceiver m_receiver ;
29
+ protected UnityEditor . Editor m_innerEditor ;
30
+ private FbxExportPresetSelectorReceiver m_receiver ;
30
31
31
32
private static GUIContent presetIcon { get { return EditorGUIUtility . IconContent ( "Preset.Context" ) ; } }
32
33
private static GUIStyle presetIconButton { get { return new GUIStyle ( "IconButton" ) ; } }
@@ -37,21 +38,11 @@ public class ExportModelEditorWindow : EditorWindow
37
38
private GUIStyle m_fbxExtLabelStyle ;
38
39
private float m_fbxExtLabelWidth ;
39
40
40
- void OnEnable ( ) {
41
+ protected virtual void OnEnable ( ) {
41
42
InitializeReceiver ( ) ;
42
43
m_showOptions = true ;
43
44
this . minSize = new Vector2 ( SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth , 220 ) ;
44
45
45
- if ( ! m_innerEditor ) {
46
- var ms = ExportSettings . instance . exportModelSettings ;
47
- if ( ! ms ) {
48
- ExportSettings . LoadSettings ( ) ;
49
- ms = ExportSettings . instance . exportModelSettings ;
50
- }
51
- m_innerEditor = UnityEditor . Editor . CreateEditor ( ms ) as ExportModelSettingsEditor ;
52
- m_innerEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
53
- }
54
-
55
46
m_nameTextFieldStyle = new GUIStyle ( GUIStyle . none ) ;
56
47
m_nameTextFieldStyle . alignment = TextAnchor . LowerCenter ;
57
48
m_nameTextFieldStyle . clipping = TextClipping . Clip ;
@@ -64,13 +55,19 @@ void OnEnable(){
64
55
m_fbxExtLabelWidth = m_fbxExtLabelStyle . CalcSize ( new GUIContent ( ".fbx" ) ) . x ;
65
56
}
66
57
67
- public static void Init ( string filename = "" , bool singleHierarchyExport = true , ModelExporter . AnimationExportType exportType = ModelExporter . AnimationExportType . all )
68
- {
69
- ExportModelEditorWindow window = ( ExportModelEditorWindow ) EditorWindow . GetWindow < ExportModelEditorWindow > ( WindowTitle , focus : true ) ;
70
- window . SetFilename ( filename ) ;
71
- window . SetAnimationExportType ( exportType ) ;
72
- window . SetSingleHierarchyExport ( singleHierarchyExport ) ;
73
- window . Show ( ) ;
58
+ protected static T CreateWindow < T > ( ) where T : EditorWindow {
59
+ return ( T ) EditorWindow . GetWindow < T > ( DefaultWindowTitle , focus : true ) ;
60
+ }
61
+
62
+ protected virtual void InitializeWindow ( string filename = "" , bool singleHierarchyExport = true , ModelExporter . AnimationExportType exportType = ModelExporter . AnimationExportType . all ) {
63
+ this . SetTitle ( ) ;
64
+ this . SetFilename ( filename ) ;
65
+ this . SetAnimationExportType ( exportType ) ;
66
+ this . SetSingleHierarchyExport ( singleHierarchyExport ) ;
67
+ }
68
+
69
+ private void SetTitle ( ) {
70
+ this . titleContent = m_windowTitle ;
74
71
}
75
72
76
73
private void InitializeReceiver ( ) {
@@ -101,7 +98,10 @@ public void SetSingleHierarchyExport(bool singleHierarchy){
101
98
m_singleHierarchyExport = singleHierarchy ;
102
99
103
100
if ( m_innerEditor ) {
104
- m_innerEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
101
+ var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor ;
102
+ if ( exportModelSettingsEditor ) {
103
+ exportModelSettingsEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
104
+ }
105
105
}
106
106
}
107
107
@@ -117,7 +117,14 @@ public void OnPresetSelectionChanged()
117
117
this . Repaint ( ) ;
118
118
}
119
119
120
- void OnGUI ( )
120
+ protected abstract void Export ( ) ;
121
+
122
+ /// <summary>
123
+ /// Function to be used by derived classes to add custom UI between the file path selector and export options.
124
+ /// </summary>
125
+ protected virtual void CreateCustomUI ( ) { }
126
+
127
+ protected void OnGUI ( )
121
128
{
122
129
// Increasing the label width so that none of the text gets cut off
123
130
EditorGUIUtility . labelWidth = LabelWidth ;
@@ -196,6 +203,8 @@ void OnGUI ()
196
203
}
197
204
GUILayout . EndHorizontal ( ) ;
198
205
206
+ CreateCustomUI ( ) ;
207
+
199
208
EditorGUILayout . Space ( ) ;
200
209
EditorGUI . indentLevel -- ;
201
210
m_showOptions = EditorGUILayout . Foldout ( m_showOptions , "Options" ) ;
@@ -213,31 +222,7 @@ void OnGUI ()
213
222
}
214
223
215
224
if ( GUILayout . Button ( "Export" , GUILayout . Width ( ExportButtonWidth ) ) ) {
216
- var filePath = ExportSettings . GetExportModelAbsoluteSavePath ( ) ;
217
-
218
- filePath = System . IO . Path . Combine ( filePath , m_exportFileName + ".fbx" ) ;
219
-
220
- // check if file already exists, give a warning if it does
221
- if ( System . IO . File . Exists ( filePath ) ) {
222
- bool overwrite = UnityEditor . EditorUtility . DisplayDialog (
223
- string . Format ( "{0} Warning" , ModelExporter . PACKAGE_UI_NAME ) ,
224
- string . Format ( "File {0} already exists." , filePath ) ,
225
- "Overwrite" , "Cancel" ) ;
226
- if ( ! overwrite ) {
227
- this . Close ( ) ;
228
-
229
- if ( GUI . changed ) {
230
- SaveExportSettings ( ) ;
231
- }
232
- return ;
233
- }
234
- }
235
-
236
- if ( ModelExporter . ExportObjects ( filePath , exportType : m_animExportType , lodExportType : ExportSettings . GetLODExportType ( ) ) != null ) {
237
- // refresh the asset database so that the file appears in the
238
- // asset folder view.
239
- AssetDatabase . Refresh ( ) ;
240
- }
225
+ Export ( ) ;
241
226
this . Close ( ) ;
242
227
}
243
228
GUILayout . EndHorizontal ( ) ;
@@ -247,5 +232,58 @@ void OnGUI ()
247
232
}
248
233
}
249
234
}
235
+
236
+ public class ExportModelEditorWindow : ExportOptionsEditorWindow
237
+ {
238
+ public static void Init ( string filename = "" , bool singleHierarchyExport = true , ModelExporter . AnimationExportType exportType = ModelExporter . AnimationExportType . all )
239
+ {
240
+ ExportModelEditorWindow window = CreateWindow < ExportModelEditorWindow > ( ) ;
241
+ window . InitializeWindow ( filename , singleHierarchyExport , exportType ) ;
242
+ window . Show ( ) ;
243
+ }
244
+
245
+ protected override void OnEnable ( )
246
+ {
247
+ base . OnEnable ( ) ;
248
+
249
+ if ( ! m_innerEditor ) {
250
+ var ms = ExportSettings . instance . exportModelSettings ;
251
+ if ( ! ms ) {
252
+ ExportSettings . LoadSettings ( ) ;
253
+ ms = ExportSettings . instance . exportModelSettings ;
254
+ }
255
+ m_innerEditor = UnityEditor . Editor . CreateEditor ( ms ) ;
256
+ this . SetSingleHierarchyExport ( m_singleHierarchyExport ) ;
257
+ }
258
+ }
259
+
260
+ protected override void Export ( ) {
261
+ var filePath = ExportSettings . GetExportModelAbsoluteSavePath ( ) ;
262
+
263
+ filePath = System . IO . Path . Combine ( filePath , m_exportFileName + ".fbx" ) ;
264
+
265
+ // check if file already exists, give a warning if it does
266
+ if ( System . IO . File . Exists ( filePath ) ) {
267
+ bool overwrite = UnityEditor . EditorUtility . DisplayDialog (
268
+ string . Format ( "{0} Warning" , ModelExporter . PACKAGE_UI_NAME ) ,
269
+ string . Format ( "File {0} already exists." , filePath ) ,
270
+ "Overwrite" , "Cancel" ) ;
271
+ if ( ! overwrite ) {
272
+ this . Close ( ) ;
273
+
274
+ if ( GUI . changed ) {
275
+ SaveExportSettings ( ) ;
276
+ }
277
+ return ;
278
+ }
279
+ }
280
+
281
+ if ( ModelExporter . ExportObjects ( filePath , exportType : m_animExportType , lodExportType : ExportSettings . GetLODExportType ( ) ) != null ) {
282
+ // refresh the asset database so that the file appears in the
283
+ // asset folder view.
284
+ AssetDatabase . Refresh ( ) ;
285
+ }
286
+ }
287
+ }
250
288
}
251
289
}
0 commit comments