// Returns the first EditorWindow of type /t/ which is currently on the screen. static EditorWindow GetWindowPrivate(System.Type t, bool utility, string title, bool focus) { UnityEngine.Object[] wins = Resources.FindObjectsOfTypeAll(t); EditorWindow win = wins.Length > 0 ? (EditorWindow)(wins[0]) : null; if (!win) { try { win = ScriptableObject.CreateInstance(t) as EditorWindow; if (title != null) { win.titleContent = new GUIContent(title); } if (utility) { win.ShowUtility(); } else { win.Show(); } } catch { win.Close(); throw; } } else if (focus) { win.Show(); // For some corner cases in saved layouts, the window can be in an unvisible state. // Since the caller asked for focus, it's fair to assume he wants it always to be visible. (case 586743) win.Focus(); } return(win); }