You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
|
3 years ago
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace UnityEditor.Polybrush
|
||
|
|
{
|
||
|
|
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 PolybrushSettings.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 = PolybrushSettings.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)
|
||
|
|
{
|
||
|
|
PolybrushSettings.Set<bool>(utilityWindowKey, isUtilityWindow, SettingsScope.Project);
|
||
|
|
PolybrushSettings.Save();
|
||
|
|
var title = titleContent;
|
||
|
|
Close();
|
||
|
|
var res = GetWindow(GetType(), isUtilityWindow);
|
||
|
|
res.titleContent = title;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|