3
3
using UnityEngine ;
4
4
using UnityEditor ;
5
5
using FbxExporters . EditorTools ;
6
+ #if UNITY_2018_1_OR_NEWER
7
+ using UnityEditor . Presets ;
8
+ #endif
6
9
using System . Linq ;
7
10
8
11
namespace FbxExporters
@@ -28,6 +31,11 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
28
31
protected string m_exportFileName = "" ;
29
32
30
33
protected UnityEditor . Editor m_innerEditor ;
34
+ #if UNITY_2018_1_OR_NEWER
35
+ protected FbxExportPresetSelectorReceiver m_receiver ;
36
+ #endif
37
+ private static GUIContent presetIcon { get { return EditorGUIUtility . IconContent ( "Preset.Context" ) ; } }
38
+ private static GUIStyle presetIconButton { get { return new GUIStyle ( "IconButton" ) ; } }
31
39
32
40
private bool m_showOptions ;
33
41
@@ -36,6 +44,9 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
36
44
protected float m_fbxExtLabelWidth ;
37
45
38
46
protected virtual void OnEnable ( ) {
47
+ #if UNITY_2018_1_OR_NEWER
48
+ InitializeReceiver ( ) ;
49
+ #endif
39
50
m_showOptions = true ;
40
51
this . minSize = new Vector2 ( SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth , MinWindowHeight ) ;
41
52
@@ -60,6 +71,18 @@ protected virtual void InitializeWindow(string filename = ""){
60
71
this . SetFilename ( filename ) ;
61
72
}
62
73
74
+ #if UNITY_2018_1_OR_NEWER
75
+ protected void InitializeReceiver ( ) {
76
+ if ( ! m_receiver ) {
77
+ m_receiver = ScriptableObject . CreateInstance < FbxExportPresetSelectorReceiver > ( ) as FbxExportPresetSelectorReceiver ;
78
+ m_receiver . SelectionChanged -= OnPresetSelectionChanged ;
79
+ m_receiver . SelectionChanged += OnPresetSelectionChanged ;
80
+ m_receiver . DialogClosed -= SaveExportSettings ;
81
+ m_receiver . DialogClosed += SaveExportSettings ;
82
+ }
83
+ }
84
+ #endif
85
+
63
86
public void SetFilename ( string filename ) {
64
87
// remove .fbx from end of filename
65
88
int extIndex = filename . LastIndexOf ( ".fbx" ) ;
@@ -93,13 +116,31 @@ protected virtual bool DisableNameSelection(){
93
116
return false ;
94
117
}
95
118
119
+ #if UNITY_2018_1_OR_NEWER
120
+ protected abstract void ShowPresetReceiver ( ) ;
121
+
122
+ protected void ShowPresetReceiver ( UnityEngine . Object target ) {
123
+ InitializeReceiver ( ) ;
124
+ m_receiver . SetTarget ( target ) ;
125
+ m_receiver . SetInitialValue ( new Preset ( target ) ) ;
126
+ UnityEditor . Presets . PresetSelector . ShowSelector ( target , null , true , m_receiver ) ;
127
+ }
128
+ #endif
129
+
96
130
protected void OnGUI ( )
97
131
{
98
132
// Increasing the label width so that none of the text gets cut off
99
133
EditorGUIUtility . labelWidth = LabelWidth ;
100
134
101
135
GUILayout . BeginHorizontal ( ) ;
102
136
GUILayout . FlexibleSpace ( ) ;
137
+
138
+ #if UNITY_2018_1_OR_NEWER
139
+ if ( EditorGUILayout . DropdownButton ( presetIcon , FocusType . Keyboard , presetIconButton ) ) {
140
+ ShowPresetReceiver ( ) ;
141
+ }
142
+ #endif
143
+
103
144
GUILayout . EndHorizontal ( ) ;
104
145
105
146
EditorGUILayout . LabelField ( "Naming" ) ;
@@ -334,6 +375,13 @@ protected override void Export(){
334
375
AssetDatabase . Refresh ( ) ;
335
376
}
336
377
}
378
+
379
+ #if UNITY_2018_1_OR_NEWER
380
+ protected override void ShowPresetReceiver ( )
381
+ {
382
+ ShowPresetReceiver ( ExportSettings . instance . exportModelSettings ) ;
383
+ }
384
+ #endif
337
385
}
338
386
}
339
387
}
0 commit comments