-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurableWindow.cs
70 lines (58 loc) · 2.44 KB
/
ConfigurableWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using UnityEngine;
namespace UnityEditor.ProBuilder
{
abstract class ConfigurableWindow : EditorWindow, IHasCustomMenu
{
protected virtual bool defaultIsUtilityWindow
{
get { return false; }
}
string utilityWindowKey
{
get { return GetType().ToString() + "-isUtilityWindow"; }
}
protected static bool IsUtilityWindow<T>(bool defaultIsUtility = false) where T : ConfigurableWindow
{
return ProBuilderSettings.Get<bool>(typeof(T).ToString() + "-isUtilityWindow", SettingsScope.Project, defaultIsUtility);
}
public static new T GetWindow<T>(string title, bool focus = true) where T : ConfigurableWindow
{
return EditorWindow.GetWindow<T>(IsUtilityWindow<T>(), title, focus);
}
/// <summary>
/// Get or create an instance of EditorWindow. Note that `utility` may be overridden by user set preference.
/// </summary>
public static new T GetWindow<T>(bool utility, string title, bool focus) where T : ConfigurableWindow
{
return EditorWindow.GetWindow<T>(IsUtilityWindow<T>(utility), title, focus);
}
public virtual void AddItemsToMenu(GenericMenu menu)
{
bool floating = ProBuilderSettings.Get<bool>(utilityWindowKey, SettingsScope.Project, false);
if (menu.GetItemCount() > 1)
menu.AddSeparator("");
menu.AddItem(new GUIContent("Open as Floating Window", ""), floating, () => SetIsUtilityWindow(true));
menu.AddItem(new GUIContent("Open as Dockable Window", ""), !floating, () => SetIsUtilityWindow(false));
menu.AddSeparator("");
}
protected void DoContextMenu()
{
var e = Event.current;
if (e.type == EventType.ContextClick)
{
var menu = new GenericMenu();
AddItemsToMenu(menu);
menu.ShowAsContext();
}
}
void SetIsUtilityWindow(bool isUtilityWindow)
{
ProBuilderSettings.Set<bool>(utilityWindowKey, isUtilityWindow, SettingsScope.Project);
ProBuilderSettings.Save();
var title = titleContent;
Close();
var res = GetWindow(GetType(), isUtilityWindow);
res.titleContent = title;
}
}
}