Skip to content

Commit e66e4ee

Browse files
committed
clean up export settings window UI
1 parent 0b26590 commit e66e4ee

File tree

1 file changed

+61
-58
lines changed

1 file changed

+61
-58
lines changed

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,51 @@ public class ExportModelEditorWindow : EditorWindow
1717
private const float BrowseButtonWidth = 25;
1818
private const float LabelWidth = 175;
1919
private const float FieldOffset = 18;
20+
private const float TextFieldAlignOffset = 3;
21+
private const float ExportButtonWidth = 100;
22+
private const float FbxExtOffset = -7;
23+
2024
private string m_exportFileName = "";
2125
private ModelExporter.AnimationExportType m_animExportType = ModelExporter.AnimationExportType.all;
2226
private bool m_singleHierarchyExport = true;
2327

24-
private ExportModelSettingsEditor innerEditor;
25-
private static FbxExportPresetSelectorReceiver receiver;
28+
private ExportModelSettingsEditor m_innerEditor;
29+
private static FbxExportPresetSelectorReceiver m_receiver;
2630

2731
private static GUIContent presetIcon { get { return EditorGUIUtility.IconContent ("Preset.Context"); }}
2832
private static GUIStyle presetIconButton { get { return new GUIStyle("IconButton"); }}
2933

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;
3139

3240
void OnEnable(){
3341
InitializeReceiver ();
34-
showOptions = true;
42+
m_showOptions = true;
3543
this.minSize = new Vector2 (SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth, 220);
3644

37-
if (!innerEditor) {
45+
if (!m_innerEditor) {
3846
var ms = ExportSettings.instance.exportModelSettings;
3947
if (!ms) {
4048
ExportSettings.LoadSettings ();
4149
ms = ExportSettings.instance.exportModelSettings;
4250
}
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);
4553
}
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;
4665
}
4766

4867
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
5574
}
5675

5776
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;
6483
}
6584
}
6685

6786
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);
6994
}
7095

7196
public void SetAnimationExportType(ModelExporter.AnimationExportType exportType){
@@ -75,12 +100,12 @@ public void SetAnimationExportType(ModelExporter.AnimationExportType exportType)
75100
public void SetSingleHierarchyExport(bool singleHierarchy){
76101
m_singleHierarchyExport = singleHierarchy;
77102

78-
if (innerEditor) {
79-
innerEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
103+
if (m_innerEditor) {
104+
m_innerEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
80105
}
81106
}
82107

83-
public void OnPresetDialogClosed()
108+
public void SaveExportSettings()
84109
{
85110
// save once preset selection is finished
86111
EditorUtility.SetDirty (ExportSettings.instance);
@@ -101,9 +126,9 @@ void OnGUI ()
101126
GUILayout.FlexibleSpace ();
102127
if(EditorGUILayout.DropdownButton(presetIcon, FocusType.Keyboard, presetIconButton)){
103128
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);
107132
}
108133
GUILayout.EndHorizontal();
109134

@@ -113,44 +138,24 @@ void OnGUI ()
113138
GUILayout.BeginHorizontal ();
114139
EditorGUILayout.LabelField(new GUIContent(
115140
"Export Name:",
116-
"Filename to save model to."),GUILayout.Width(LabelWidth-3));
141+
"Filename to save model to."),GUILayout.Width(LabelWidth-TextFieldAlignOffset));
117142

118143
// Show the export name with an uneditable ".fbx" at the end
144+
//-------------------------------------
119145
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));
122147
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));
135151
m_exportFileName = ModelExporter.ConvertToValidFilename (m_exportFileName);
136152

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));
145154
EditorGUI.indentLevel++;
146155

147156
EditorGUILayout.EndHorizontal();
148157
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+
//-----------------------------------
154159
GUILayout.EndHorizontal ();
155160

156161
GUILayout.BeginHorizontal();
@@ -193,24 +198,24 @@ void OnGUI ()
193198

194199
EditorGUILayout.Space ();
195200
EditorGUI.indentLevel--;
196-
showOptions = EditorGUILayout.Foldout (showOptions, "Options");
201+
m_showOptions = EditorGUILayout.Foldout (m_showOptions, "Options");
197202
EditorGUI.indentLevel++;
198-
if (showOptions) {
199-
innerEditor.OnInspectorGUI ();
203+
if (m_showOptions) {
204+
m_innerEditor.OnInspectorGUI ();
200205
}
201206

202207
GUILayout.FlexibleSpace ();
203208

204209
GUILayout.BeginHorizontal ();
205210
GUILayout.FlexibleSpace ();
206-
if (GUILayout.Button ("Cancel", GUILayout.Width(100))) {
211+
if (GUILayout.Button ("Cancel", GUILayout.Width(ExportButtonWidth))) {
207212
this.Close ();
208213
}
209214

210-
if (GUILayout.Button ("Export", GUILayout.Width(100))) {
215+
if (GUILayout.Button ("Export", GUILayout.Width(ExportButtonWidth))) {
211216
var filePath = ExportSettings.GetExportModelAbsoluteSavePath ();
212217

213-
filePath = System.IO.Path.Combine (filePath, m_exportFileName);
218+
filePath = System.IO.Path.Combine (filePath, m_exportFileName + ".fbx");
214219

215220
// check if file already exists, give a warning if it does
216221
if (System.IO.File.Exists (filePath)) {
@@ -222,8 +227,7 @@ void OnGUI ()
222227
this.Close ();
223228

224229
if (GUI.changed) {
225-
EditorUtility.SetDirty (ExportSettings.instance);
226-
ExportSettings.instance.Save ();
230+
SaveExportSettings ();
227231
}
228232
return;
229233
}
@@ -239,8 +243,7 @@ void OnGUI ()
239243
GUILayout.EndHorizontal ();
240244

241245
if (GUI.changed) {
242-
EditorUtility.SetDirty (ExportSettings.instance);
243-
ExportSettings.instance.Save ();
246+
SaveExportSettings ();
244247
}
245248
}
246249
}

0 commit comments

Comments
 (0)