/// <summary> Make the EditorWindow into a fullscreen window, with the option to show the top tabs. Opens the fullscreen window on the screen at a specified position. </summary> private static Rect MakeFullscreenWindow(this EditorWindow editorWindow, bool hideTopToolbar, Vector2 atPosition) { var winRect = EditorDisplay.ClosestToPoint(atPosition).Bounds; if (hideTopToolbar == true) { /*Move the top tab off the screen*/ winRect.y -= FS.topTabFullHeight; winRect.height += FS.topTabFullHeight; } editorWindow.SetBorderlessPosition(winRect, hideTopToolbar); #if UNITY_STANDALONE_WIN //Fix positioning bug when monitors have differing scale var sysDisplays = SystemDisplay.GetAllDisplays(); var fullscreenDisp = sysDisplays.ClosestToPoint(atPosition); var mainWindowDisp = sysDisplays.WithMainWindow(); if (fullscreenDisp != mainWindowDisp) { //Check if there is a scaling difference between the main window display and the fullscreen display. float fullscreenDispScale = fullscreenDisp.PixelWidth / fullscreenDisp.Bounds.width; float mainWindowDispScale = mainWindowDisp.PixelWidth / mainWindowDisp.Bounds.width; if (fullscreenDispScale != mainWindowDispScale) { //There is a scaling difference, so adjust the winRect to account for the scaling. (Because the window is positioned based on the scaling of the main window display). float relativeScale = fullscreenDispScale / mainWindowDispScale; winRect.x = winRect.x * relativeScale; winRect.y = winRect.y * relativeScale; winRect.width = winRect.width * relativeScale; winRect.height = winRect.height * relativeScale; } editorWindow.SetBorderlessPosition(winRect, hideTopToolbar); //Call system SetWindowPosition to make sure the window covers the taskbar SystemDisplay.MakeWindowCoverTaskBar(editorWindow.GetWindowTitle(), fullscreenDisp); //Hide the top toolbar if necessary. editorWindow.SetToolbarVisibilityAtPos(winRect, hideTopToolbar, false); } #endif return(winRect); }
/// <summary> /// Get all the displays which are attached to the desktop (As a List) /// </summary> public static List <EditorDisplay> GetAllDisplays() { EWFDebugging.StartTimer("GetAllDisplays"); List <EditorDisplay> allDisplays = new List <EditorDisplay>(); try { #if UNITY_EDITOR_OSX //Get system displays allDisplays = FromSystemDisplays(SystemDisplay.GetAllDisplays()); #else allDisplays = FromSystemDisplays(SystemDisplay.GetAllDisplays()); //If couldn't find system displays, use backup method if (allDisplays == null || allDisplays.Count < 1) { var desktopBounds = PrimaryDesktopResolution; allDisplays = new List <EditorDisplay>(); //Find all the displays var display = AddDisplayAtPoint(allDisplays, desktopBounds.center, true); if (display != null) { AddContiguousDisplays(allDisplays, display); } } #endif } catch (Exception e) { if (EWFDebugging.Enabled) { string err = "Failed to find all possible displays. " + e; Debug.LogError(err); EWFDebugging.LogError(err); } } if (allDisplays.Count == 0) { /*Failed to find the displays, so add the primary Screen as a display*/ var display = new EditorDisplay(new Rect(0, 0, Screen.currentResolution.width, Screen.currentResolution.height)); allDisplays.Add(display); } //Sort screens by top-left to bottom-right allDisplays.Sort(delegate(EditorDisplay a, EditorDisplay b) { bool aIsLess; if (a.Bounds.y != b.Bounds.y) { aIsLess = a.Bounds.y < b.Bounds.y; } else { if (a.Bounds.x == b.Bounds.x) { return(0); //Equal } else { aIsLess = a.Bounds.x < b.Bounds.x; } } return(aIsLess ? -1 : 1); }); EWFDebugging.LogTime("GetAllDisplays", false); EditorDisplay.allDisplays = allDisplays; return(allDisplays); }