public static bool Open <T>(SearchWindowContext context, T provider) where T : ScriptableObject, ISearchWindowProvider { // If the window is already open, close it instead. UnityEngine.Object[] wins = Resources.FindObjectsOfTypeAll(typeof(SearchWindow)); if (wins.Length > 0) { try { ((EditorWindow)wins[0]).Close(); return(false); } catch (Exception) { s_FilterWindow = null; } } // We could not use realtimeSinceStartUp since it is set to 0 when entering/exitting playmode, we assume an increasing time when comparing time. long nowMilliSeconds = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond; bool justClosed = nowMilliSeconds < s_LastClosedTime + 50; if (!justClosed) { if (s_FilterWindow == null) { s_FilterWindow = ScriptableObject.CreateInstance <SearchWindow>(); s_FilterWindow.hideFlags = HideFlags.HideAndDontSave; } s_FilterWindow.Init(context, provider); return(true); } return(false); }
void Init(SearchWindowContext context, ScriptableObject provider) { m_Owner = provider; m_Context = context; float width = Math.Max(context.requestedWidth, k_DefaultWidth); float height = Math.Max(context.requestedHeight, k_DefaultHeight); Rect buttonRect = new Rect(context.screenMousePosition.x - width / 2, context.screenMousePosition.y - k_WindowYOffset, width, 1); CreateSearchTree(); ShowAsDropDown(buttonRect, new Vector2(buttonRect.width, height)); Focus(); wantsMouseMove = true; }