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(bool defaultIsUtility = false) where T : ConfigurableWindow { return PolybrushSettings.Get(typeof(T).ToString() + "-isUtilityWindow", SettingsScope.Project, defaultIsUtility); } public static new T GetWindow(string title, bool focus = true) where T : ConfigurableWindow { return EditorWindow.GetWindow(IsUtilityWindow(), title, focus); } /// /// Get or create an instance of EditorWindow. Note that `utility` may be overridden by user set preference. /// public static new T GetWindow(bool utility, string title, bool focus) where T : ConfigurableWindow { return EditorWindow.GetWindow(IsUtilityWindow(utility), title, focus); } public virtual void AddItemsToMenu(GenericMenu menu) { bool floating = PolybrushSettings.Get(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(utilityWindowKey, isUtilityWindow, SettingsScope.Project); PolybrushSettings.Save(); var title = titleContent; Close(); var res = GetWindow(GetType(), isUtilityWindow); res.titleContent = title; } } }