@@ -17,32 +17,51 @@ public class ExportModelEditorWindow : EditorWindow
17
17
private const float BrowseButtonWidth = 25 ;
18
18
private const float LabelWidth = 175 ;
19
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
+
20
24
private string m_exportFileName = "" ;
21
25
private ModelExporter . AnimationExportType m_animExportType = ModelExporter . AnimationExportType . all ;
22
26
private bool m_singleHierarchyExport = true ;
23
27
24
- private ExportModelSettingsEditor innerEditor ;
25
- private static FbxExportPresetSelectorReceiver receiver ;
28
+ private ExportModelSettingsEditor m_innerEditor ;
29
+ private static FbxExportPresetSelectorReceiver m_receiver ;
26
30
27
31
private static GUIContent presetIcon { get { return EditorGUIUtility . IconContent ( "Preset.Context" ) ; } }
28
32
private static GUIStyle presetIconButton { get { return new GUIStyle ( "IconButton" ) ; } }
29
33
30
- private bool showOptions ;
34
+ private bool m_showOptions ;
35
+
36
+ private GUIStyle m_nameTextFieldStyle ;
37
+ private GUIStyle m_fbxExtLabelStyle ;
38
+ private float m_fbxExtLabelWidth ;
31
39
32
40
void OnEnable ( ) {
33
41
InitializeReceiver ( ) ;
34
- showOptions = true ;
42
+ m_showOptions = true ;
35
43
this . minSize = new Vector2 ( SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth , 220 ) ;
36
44
37
- if ( ! innerEditor ) {
45
+ if ( ! m_innerEditor ) {
38
46
var ms = ExportSettings . instance . exportModelSettings ;
39
47
if ( ! ms ) {
40
48
ExportSettings . LoadSettings ( ) ;
41
49
ms = ExportSettings . instance . exportModelSettings ;
42
50
}
43
- innerEditor = UnityEditor . Editor . CreateEditor ( ms ) as ExportModelSettingsEditor ;
44
- innerEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
51
+ m_innerEditor = UnityEditor . Editor . CreateEditor ( ms ) as ExportModelSettingsEditor ;
52
+ m_innerEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
45
53
}
54
+
55
+ m_nameTextFieldStyle = new GUIStyle ( GUIStyle . none ) ;
56
+ m_nameTextFieldStyle . alignment = TextAnchor . LowerCenter ;
57
+ m_nameTextFieldStyle . clipping = TextClipping . Clip ;
58
+
59
+ m_fbxExtLabelStyle = new GUIStyle ( GUIStyle . none ) ;
60
+ m_fbxExtLabelStyle . alignment = TextAnchor . MiddleLeft ;
61
+ m_fbxExtLabelStyle . richText = true ;
62
+ m_fbxExtLabelStyle . contentOffset = new Vector2 ( FbxExtOffset , 0 ) ;
63
+
64
+ m_fbxExtLabelWidth = m_fbxExtLabelStyle . CalcSize ( new GUIContent ( ".fbx" ) ) . x ;
46
65
}
47
66
48
67
public static void Init ( string filename = "" , bool singleHierarchyExport = true , ModelExporter . AnimationExportType exportType = ModelExporter . AnimationExportType . all )
@@ -55,17 +74,23 @@ public static void Init (string filename = "", bool singleHierarchyExport = true
55
74
}
56
75
57
76
private void InitializeReceiver ( ) {
58
- if ( ! receiver ) {
59
- receiver = ScriptableObject . CreateInstance < FbxExportPresetSelectorReceiver > ( ) as FbxExportPresetSelectorReceiver ;
60
- receiver . SelectionChanged -= OnPresetSelectionChanged ;
61
- receiver . SelectionChanged += OnPresetSelectionChanged ;
62
- receiver . DialogClosed -= OnPresetDialogClosed ;
63
- receiver . DialogClosed += OnPresetDialogClosed ;
77
+ if ( ! m_receiver ) {
78
+ m_receiver = ScriptableObject . CreateInstance < FbxExportPresetSelectorReceiver > ( ) as FbxExportPresetSelectorReceiver ;
79
+ m_receiver . SelectionChanged -= OnPresetSelectionChanged ;
80
+ m_receiver . SelectionChanged += OnPresetSelectionChanged ;
81
+ m_receiver . DialogClosed -= SaveExportSettings ;
82
+ m_receiver . DialogClosed += SaveExportSettings ;
64
83
}
65
84
}
66
85
67
86
public void SetFilename ( string filename ) {
68
- m_exportFileName = filename ;
87
+ // remove .fbx from end of filename
88
+ int extIndex = filename . LastIndexOf ( ".fbx" ) ;
89
+ if ( extIndex < 0 ) {
90
+ m_exportFileName = filename ;
91
+ return ;
92
+ }
93
+ m_exportFileName = filename . Remove ( extIndex ) ;
69
94
}
70
95
71
96
public void SetAnimationExportType ( ModelExporter . AnimationExportType exportType ) {
@@ -75,12 +100,12 @@ public void SetAnimationExportType(ModelExporter.AnimationExportType exportType)
75
100
public void SetSingleHierarchyExport ( bool singleHierarchy ) {
76
101
m_singleHierarchyExport = singleHierarchy ;
77
102
78
- if ( innerEditor ) {
79
- innerEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
103
+ if ( m_innerEditor ) {
104
+ m_innerEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
80
105
}
81
106
}
82
107
83
- public void OnPresetDialogClosed ( )
108
+ public void SaveExportSettings ( )
84
109
{
85
110
// save once preset selection is finished
86
111
EditorUtility . SetDirty ( ExportSettings . instance ) ;
@@ -101,9 +126,9 @@ void OnGUI ()
101
126
GUILayout . FlexibleSpace ( ) ;
102
127
if ( EditorGUILayout . DropdownButton ( presetIcon , FocusType . Keyboard , presetIconButton ) ) {
103
128
InitializeReceiver ( ) ;
104
- receiver . SetTarget ( ExportSettings . instance . exportModelSettings ) ;
105
- receiver . SetInitialValue ( new Preset ( ExportSettings . instance . exportModelSettings ) ) ;
106
- UnityEditor . Presets . PresetSelector . ShowSelector ( ExportSettings . instance . exportModelSettings , null , true , receiver ) ;
129
+ m_receiver . SetTarget ( ExportSettings . instance . exportModelSettings ) ;
130
+ m_receiver . SetInitialValue ( new Preset ( ExportSettings . instance . exportModelSettings ) ) ;
131
+ UnityEditor . Presets . PresetSelector . ShowSelector ( ExportSettings . instance . exportModelSettings , null , true , m_receiver ) ;
107
132
}
108
133
GUILayout . EndHorizontal ( ) ;
109
134
@@ -113,44 +138,24 @@ void OnGUI ()
113
138
GUILayout . BeginHorizontal ( ) ;
114
139
EditorGUILayout . LabelField ( new GUIContent (
115
140
"Export Name:" ,
116
- "Filename to save model to." ) , GUILayout . Width ( LabelWidth - 3 ) ) ;
141
+ "Filename to save model to." ) , GUILayout . Width ( LabelWidth - TextFieldAlignOffset ) ) ;
117
142
118
143
// Show the export name with an uneditable ".fbx" at the end
144
+ //-------------------------------------
119
145
EditorGUILayout . BeginVertical ( ) ;
120
- var style = new GUIStyle ( EditorStyles . textField ) ;
121
- EditorGUILayout . BeginHorizontal ( style , GUILayout . Height ( EditorGUIUtility . singleLineHeight ) ) ;
146
+ EditorGUILayout . BeginHorizontal ( EditorStyles . textField , GUILayout . Height ( EditorGUIUtility . singleLineHeight ) ) ;
122
147
EditorGUI . indentLevel -- ;
123
-
124
- var textFieldStyle = new GUIStyle ( GUIStyle . none ) ;
125
- textFieldStyle . alignment = TextAnchor . LowerCenter ;
126
- textFieldStyle . margin = new RectOffset ( 0 , 0 , 0 , 0 ) ;
127
- var padding = textFieldStyle . padding ;
128
- padding . left = 0 ;
129
- padding . right = 0 ;
130
- textFieldStyle . padding = padding ;
131
- textFieldStyle . clipping = TextClipping . Clip ;
132
-
133
- var textFieldSize = textFieldStyle . CalcSize ( new GUIContent ( m_exportFileName ) ) ;
134
- m_exportFileName = EditorGUILayout . TextField ( m_exportFileName , textFieldStyle , GUILayout . Width ( textFieldSize . x + 5 ) , GUILayout . MinWidth ( 5 ) ) ;
148
+ // continually resize to contents
149
+ var textFieldSize = m_nameTextFieldStyle . CalcSize ( new GUIContent ( m_exportFileName ) ) ;
150
+ m_exportFileName = EditorGUILayout . TextField ( m_exportFileName , m_nameTextFieldStyle , GUILayout . Width ( textFieldSize . x + 5 ) , GUILayout . MinWidth ( 5 ) ) ;
135
151
m_exportFileName = ModelExporter . ConvertToValidFilename ( m_exportFileName ) ;
136
152
137
- var labelStyle = new GUIStyle ( GUIStyle . none ) ;
138
- labelStyle . alignment = TextAnchor . MiddleLeft ;
139
- labelStyle . richText = true ;
140
- labelStyle . margin = new RectOffset ( 0 , 0 , 0 , 0 ) ;
141
- labelStyle . padding = new RectOffset ( 0 , 0 , 0 , 0 ) ;
142
- labelStyle . contentOffset = new Vector2 ( - 7 , 0 ) ;
143
- var fbxLabelWidth = labelStyle . CalcSize ( new GUIContent ( ".fbx" ) ) . x ;
144
- EditorGUILayout . LabelField ( "<color=#808080ff>.fbx</color>" , labelStyle , GUILayout . Width ( fbxLabelWidth ) ) ;
153
+ EditorGUILayout . LabelField ( "<color=#808080ff>.fbx</color>" , m_fbxExtLabelStyle , GUILayout . Width ( m_fbxExtLabelWidth ) ) ;
145
154
EditorGUI . indentLevel ++ ;
146
155
147
156
EditorGUILayout . EndHorizontal ( ) ;
148
157
EditorGUILayout . EndVertical ( ) ;
149
- /*m_exportFileName = EditorGUILayout.TextField (m_exportFileName);
150
- if (!m_exportFileName.EndsWith (".fbx")) {
151
- m_exportFileName += ".fbx";
152
- }
153
- m_exportFileName = ModelExporter.ConvertToValidFilename(m_exportFileName);*/
158
+ //-----------------------------------
154
159
GUILayout . EndHorizontal ( ) ;
155
160
156
161
GUILayout . BeginHorizontal ( ) ;
@@ -193,24 +198,24 @@ void OnGUI ()
193
198
194
199
EditorGUILayout . Space ( ) ;
195
200
EditorGUI . indentLevel -- ;
196
- showOptions = EditorGUILayout . Foldout ( showOptions , "Options" ) ;
201
+ m_showOptions = EditorGUILayout . Foldout ( m_showOptions , "Options" ) ;
197
202
EditorGUI . indentLevel ++ ;
198
- if ( showOptions ) {
199
- innerEditor . OnInspectorGUI ( ) ;
203
+ if ( m_showOptions ) {
204
+ m_innerEditor . OnInspectorGUI ( ) ;
200
205
}
201
206
202
207
GUILayout . FlexibleSpace ( ) ;
203
208
204
209
GUILayout . BeginHorizontal ( ) ;
205
210
GUILayout . FlexibleSpace ( ) ;
206
- if ( GUILayout . Button ( "Cancel" , GUILayout . Width ( 100 ) ) ) {
211
+ if ( GUILayout . Button ( "Cancel" , GUILayout . Width ( ExportButtonWidth ) ) ) {
207
212
this . Close ( ) ;
208
213
}
209
214
210
- if ( GUILayout . Button ( "Export" , GUILayout . Width ( 100 ) ) ) {
215
+ if ( GUILayout . Button ( "Export" , GUILayout . Width ( ExportButtonWidth ) ) ) {
211
216
var filePath = ExportSettings . GetExportModelAbsoluteSavePath ( ) ;
212
217
213
- filePath = System . IO . Path . Combine ( filePath , m_exportFileName ) ;
218
+ filePath = System . IO . Path . Combine ( filePath , m_exportFileName + ".fbx" ) ;
214
219
215
220
// check if file already exists, give a warning if it does
216
221
if ( System . IO . File . Exists ( filePath ) ) {
@@ -222,8 +227,7 @@ void OnGUI ()
222
227
this . Close ( ) ;
223
228
224
229
if ( GUI . changed ) {
225
- EditorUtility . SetDirty ( ExportSettings . instance ) ;
226
- ExportSettings . instance . Save ( ) ;
230
+ SaveExportSettings ( ) ;
227
231
}
228
232
return ;
229
233
}
@@ -239,8 +243,7 @@ void OnGUI ()
239
243
GUILayout . EndHorizontal ( ) ;
240
244
241
245
if ( GUI . changed ) {
242
- EditorUtility . SetDirty ( ExportSettings . instance ) ;
243
- ExportSettings . instance . Save ( ) ;
246
+ SaveExportSettings ( ) ;
244
247
}
245
248
}
246
249
}
0 commit comments