Skip to content

Commit 15e2435

Browse files
committed
change/create preset using custom presetselectorreceiver
1 parent 6d76850 commit 15e2435

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using UnityEditor;
55
using FbxExporters.EditorTools;
6+
using UnityEditor.Presets;
67

78
namespace FbxExporters
89
{
@@ -21,15 +22,30 @@ public class ExportModelEditorWindow : EditorWindow
2122

2223
private UnityEditor.Editor innerEditor;
2324

25+
private static FbxExportPresetSelectorReceiver receiver;
26+
2427
public static void Init (string filename = "", ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all)
2528
{
2629
ExportModelEditorWindow window = (ExportModelEditorWindow)EditorWindow.GetWindow <ExportModelEditorWindow>(WindowTitle, focus:true);
2730
window.SetFilename (filename);
2831
window.SetAnimationExportType (exportType);
2932
window.minSize = new Vector2 (SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth, 100);
33+
34+
window.InitializeReceiver ();
35+
3036
window.Show ();
3137
}
3238

39+
private void InitializeReceiver(){
40+
if (!receiver) {
41+
receiver = ScriptableObject.CreateInstance<FbxExportPresetSelectorReceiver> () as FbxExportPresetSelectorReceiver;
42+
receiver.SelectionChanged -= OnPresetSelectionChanged;
43+
receiver.SelectionChanged += OnPresetSelectionChanged;
44+
receiver.DialogClosed -= OnPresetDialogClosed;
45+
receiver.DialogClosed += OnPresetDialogClosed;
46+
}
47+
}
48+
3349
public void SetFilename(string filename){
3450
m_exportFileName = filename;
3551
}
@@ -38,6 +54,18 @@ public void SetAnimationExportType(ModelExporter.AnimationExportType exportType)
3854
m_animExportType = exportType;
3955
}
4056

57+
public void OnPresetDialogClosed()
58+
{
59+
// save once preset selection is finished
60+
EditorUtility.SetDirty (ExportSettings.instance);
61+
ExportSettings.instance.Save ();
62+
}
63+
64+
public void OnPresetSelectionChanged()
65+
{
66+
this.Repaint ();
67+
}
68+
4169
void OnGUI ()
4270
{
4371
// Increasing the label width so that none of the text gets cut off
@@ -110,9 +138,16 @@ void OnGUI ()
110138
}
111139
innerEditor = UnityEditor.Editor.CreateEditor (ms, editorType: typeof(ExportModelSettingsEditor));
112140
}
113-
innerEditor.DrawHeader ();
141+
//innerEditor.DrawHeader ();
114142
innerEditor.OnInspectorGUI ();
115143

144+
if (GUILayout.Button ("select preset")) {
145+
InitializeReceiver ();
146+
receiver.SetTarget(ExportSettings.instance.exportModelSettings);
147+
receiver.SetInitialValue (new Preset (ExportSettings.instance.exportModelSettings));
148+
UnityEditor.Presets.PresetSelector.ShowSelector(ExportSettings.instance.exportModelSettings, null, true, receiver);
149+
}
150+
116151
GUILayout.FlexibleSpace ();
117152

118153
GUILayout.BeginHorizontal ();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor.Presets;
5+
6+
public class FbxExportPresetSelectorReceiver : PresetSelectorReceiver
7+
{
8+
UnityEngine.Object m_Target;
9+
Preset m_InitialValue;
10+
11+
public delegate void SelectionChangedDelegate();
12+
public event SelectionChangedDelegate SelectionChanged;
13+
14+
public delegate void DialogClosedDelegate();
15+
public event DialogClosedDelegate DialogClosed;
16+
17+
public override void OnSelectionClosed(Preset selection)
18+
{
19+
OnSelectionChanged(selection);
20+
if (DialogClosed != null) {
21+
DialogClosed ();
22+
}
23+
DestroyImmediate(this);
24+
}
25+
26+
public override void OnSelectionChanged(Preset selection)
27+
{
28+
if (selection != null)
29+
{
30+
selection.ApplyTo(m_Target);
31+
}
32+
else
33+
{
34+
m_InitialValue.ApplyTo(m_Target);
35+
}
36+
if (SelectionChanged != null) {
37+
SelectionChanged ();
38+
}
39+
}
40+
41+
public void SetTarget(UnityEngine.Object target){
42+
m_Target = target;
43+
}
44+
45+
public void SetInitialValue(Preset initialValue){
46+
m_InitialValue = initialValue;
47+
}
48+
}

Assets/FbxExporters/Editor/FbxExportPresetSelectorReceiver.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)