Skip to content

Commit 0091397

Browse files
committed
Added previous code with ifdef
1 parent e3a1803 commit 0091397

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
using UnityEngine;
44
using UnityEditor;
55
using FbxExporters.EditorTools;
6+
#if UNITY_2018_1_OR_NEWER
7+
using UnityEditor.Presets;
8+
#endif
69
using System.Linq;
710

811
namespace FbxExporters
@@ -83,7 +86,12 @@ protected override bool DisableNameSelection ()
8386
{
8487
return m_toConvert.Length > 1;
8588
}
86-
89+
#if UNITY_2018_1_OR_NEWER
90+
protected override void ShowPresetReceiver ()
91+
{
92+
ShowPresetReceiver (ExportSettings.instance.convertToPrefabSettings);
93+
}
94+
#endif
8795
protected override void CreateCustomUI ()
8896
{
8997
GUILayout.BeginHorizontal ();

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
using UnityEngine;
44
using UnityEditor;
55
using FbxExporters.EditorTools;
6+
#if UNITY_2018_1_OR_NEWER
7+
using UnityEditor.Presets;
8+
#endif
69
using System.Linq;
710

811
namespace FbxExporters
@@ -28,6 +31,11 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
2831
protected string m_exportFileName = "";
2932

3033
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"); }}
3139

3240
private bool m_showOptions;
3341

@@ -36,6 +44,9 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
3644
protected float m_fbxExtLabelWidth;
3745

3846
protected virtual void OnEnable(){
47+
#if UNITY_2018_1_OR_NEWER
48+
InitializeReceiver ();
49+
#endif
3950
m_showOptions = true;
4051
this.minSize = new Vector2 (SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth, MinWindowHeight);
4152

@@ -60,6 +71,18 @@ protected virtual void InitializeWindow(string filename = ""){
6071
this.SetFilename (filename);
6172
}
6273

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+
6386
public void SetFilename(string filename){
6487
// remove .fbx from end of filename
6588
int extIndex = filename.LastIndexOf(".fbx");
@@ -93,13 +116,31 @@ protected virtual bool DisableNameSelection(){
93116
return false;
94117
}
95118

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+
96130
protected void OnGUI ()
97131
{
98132
// Increasing the label width so that none of the text gets cut off
99133
EditorGUIUtility.labelWidth = LabelWidth;
100134

101135
GUILayout.BeginHorizontal ();
102136
GUILayout.FlexibleSpace ();
137+
138+
#if UNITY_2018_1_OR_NEWER
139+
if(EditorGUILayout.DropdownButton(presetIcon, FocusType.Keyboard, presetIconButton)){
140+
ShowPresetReceiver ();
141+
}
142+
#endif
143+
103144
GUILayout.EndHorizontal();
104145

105146
EditorGUILayout.LabelField("Naming");
@@ -334,6 +375,13 @@ protected override void Export(){
334375
AssetDatabase.Refresh ();
335376
}
336377
}
378+
379+
#if UNITY_2018_1_OR_NEWER
380+
protected override void ShowPresetReceiver ()
381+
{
382+
ShowPresetReceiver (ExportSettings.instance.exportModelSettings);
383+
}
384+
#endif
337385
}
338386
}
339387
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#if UNITY_2018_1_OR_NEWER
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
using UnityEditor.Presets;
6+
7+
public class FbxExportPresetSelectorReceiver : PresetSelectorReceiver
8+
{
9+
UnityEngine.Object m_Target;
10+
Preset m_InitialValue;
11+
12+
public delegate void SelectionChangedDelegate();
13+
public event SelectionChangedDelegate SelectionChanged;
14+
15+
public delegate void DialogClosedDelegate();
16+
public event DialogClosedDelegate DialogClosed;
17+
18+
public override void OnSelectionClosed(Preset selection)
19+
{
20+
OnSelectionChanged(selection);
21+
if (DialogClosed != null) {
22+
DialogClosed ();
23+
}
24+
DestroyImmediate(this);
25+
}
26+
27+
public override void OnSelectionChanged(Preset selection)
28+
{
29+
if (selection != null)
30+
{
31+
selection.ApplyTo(m_Target);
32+
}
33+
else
34+
{
35+
m_InitialValue.ApplyTo(m_Target);
36+
}
37+
if (SelectionChanged != null) {
38+
SelectionChanged ();
39+
}
40+
}
41+
42+
public void SetTarget(UnityEngine.Object target){
43+
m_Target = target;
44+
}
45+
46+
public void SetInitialValue(Preset initialValue){
47+
m_InitialValue = initialValue;
48+
}
49+
}
50+
#endif

0 commit comments

Comments
 (0)