private static WindowFullscreenState AddWindowState(EditorWindow editorWin, Type windowType, Type actualType) { var winState = new WindowFullscreenState(); winState.WindowType = windowType; winState.ActualType = actualType; if (editorWin != null) { winState.SetEditorWin(editorWin); } else if (windowType == mainWindowType) { winState.WindowName = mainWindowType.Name; winState.WindowTitle = "Unity Editor"; winState.containerWindow = (ScriptableObject)EditorMainWindow.FindContainerWindow(); winState.originalContainerWindow = winState.containerWindow; } if (fullscreenState.window == null) { fullscreenState.window = new List <WindowFullscreenState>(); } fullscreenState.window.Add(winState); return(winState); }
/// <summary> Toggle the toolbar in the active window if it is fullscreen </summary> public static bool ToggleToolbarInFullscreen() { bool setShowTopToolbar = false; var fullscreenWinState = FocusedWindowState; if (fullscreenWinState == null || !fullscreenWinState.IsFullscreen) { //If the current EditorWindow state isn't fullscreen, toggle the toolbar of the main window if that is fullscreen. fullscreenWinState = EditorMainWindow.GetWindowFullscreenState(); } //If no fullscreen window is focused, toggle the top tab for the last top-tab-toggled fullscreen window. if ((fullscreenWinState == null || !fullscreenWinState.IsFullscreen) && lastWinStateToToggleTopTabs != null) { fullscreenWinState = lastWinStateToToggleTopTabs; } if (fullscreenWinState != null) { lastWinStateToToggleTopTabs = fullscreenWinState; setShowTopToolbar = !fullscreenWinState.ShowTopToolbar; return(ToggleToolbarInFullscreen(fullscreenWinState, setShowTopToolbar)); } else { lastWinStateToToggleTopTabs = null; return(false); } }
public static WindowFullscreenState FindWindowState(EditorWindow editorWin, System.Type windowType, EditorDisplay editorDisplay) { WindowFullscreenState winState = null; Type actualType = windowType; windowType = GetWindowType(actualType); try { if (editorWin != null) { winState = fullscreenState.window.Find(state => state.EditorWin == editorWin && (editorDisplay == null || state.EditorWin.GetFullscreenDisplay().Bounds.Equals(editorDisplay.Bounds))); } else { winState = fullscreenState.window.Find(state => (state.EditorWin != null || state.containerWindow != null) && state.WindowType == windowType && (editorDisplay == null || state.EditorWin != null && state.EditorWin.GetFullscreenDisplay() != null && state.EditorWin.GetFullscreenDisplay().Bounds.Equals(editorDisplay.Bounds))); } } catch (System.Exception e) { if (LogNonFatalErrors) { Debug.LogError("Error attempting to find window state."); Debug.LogException(e); } } if (winState == null) { winState = AddWindowState(editorWin, windowType, actualType); } return(winState); }
public void TestConstructor() { // Define variables and constants const uint TEST_HEIGHT_PX = 123; const uint TEST_WIDTH_PX = 234; const WindowFullscreenState TEST_FULLSCREEN_STATE = WindowFullscreenState.NotFullscreen; // Set up context // Execute Window testWindow = new Window( "Unit test window", TEST_WIDTH_PX, TEST_HEIGHT_PX, TEST_FULLSCREEN_STATE, MultibufferLevel.Triple ); // Assert outcome Assert.AreEqual(TEST_WIDTH_PX, testWindow.Width); Assert.AreEqual(TEST_HEIGHT_PX, testWindow.Height); Assert.AreEqual(TEST_FULLSCREEN_STATE, testWindow.FullscreenState); testWindow.Close(); }
/// <summary> Toggle fullscreen for a window state, on the screen at position </summary> private static bool ToggleFullscreen(WindowFullscreenState windowState, bool createNewWindow, Vector2 atPosition) { if (windowState == null) { throw new NullReferenceException("windowState is null. Cannot continue."); } if (!loadedInitialState) { windowState.CloseOnExitFullscreen = createNewWindow; windowState.FullscreenAtPosition = atPosition; queuedStatesToToggleOnLoad.Add(windowState); if (LogNonFatalErrors) { throw new TypeLoadException("The fullscreen state hasn't been loaded yet. Fullscreen toggle has been queued."); } else { return(false); } } if (windowState.WindowType == mainWindowType) { return(EditorMainWindow.ToggleFullscreen(windowState.ShowTopToolbar, atPosition)); } if (windowState.EditorWin == null || (!windowState.IsFullscreen && createNewWindow)) { if (windowState.ActualType == typeof(SceneView)) { windowState.ActualType = typeof(CustomSceneView); } //Always create CustomSceneView for SceneView var win = EditorWindowExtensions.CreateWindow(windowState.ActualType); windowState.SetEditorWin(win); if (windowState.ActualType == typeof(CustomSceneView) || win.GetWindowType() == gameViewType) { win.SetWindowTitle(windowState.WindowName, true); //Reset title content on custom Scene and Game views to prevent icon not found error. } windowState.CloseOnExitFullscreen = true; //Since we are creating a new window, this window should close when fullscreen is exited bool setFullscreen = win.ToggleFullscreen(atPosition); return(setFullscreen); } else { return(windowState.EditorWin.ToggleFullscreen(atPosition)); } }
/// <summary> Toggle the toolbar for the specified window state, if it is fullscreen </summary> public static bool ToggleToolbarInFullscreen(WindowFullscreenState fullscreenWinState, bool showTopToolbar) { if (fullscreenWinState != null && fullscreenWinState.IsFullscreen) { if (fullscreenWinState.WindowType == mainWindowType) { EditorMainWindow.SetFullscreen(true, showTopToolbar); } else if (fullscreenWinState.EditorWin != null) { fullscreenWinState.EditorWin.SetFullscreen(true, showTopToolbar); } } return(showTopToolbar); }
/// <summary> Toggle fullscreen for a window state </summary> private static bool ToggleFullscreen(WindowFullscreenState windowState, bool createNewWindow) { if (windowState.EditorWin != null) { return(ToggleFullscreen(windowState, createNewWindow, windowState.EditorWin.GetFullscreenDisplay().Bounds.center)); } else if (windowState.WindowType == mainWindowType) { return(ToggleFullscreen(windowState, createNewWindow, EditorMainWindow.position.center)); } else { return(ToggleFullscreen(windowState, createNewWindow, EditorDisplay.PrimaryDesktopResolution.center)); } }
public static extern InteropBool WindowFactory_SetFullscreenState( IntPtr failReason, WindowHandle windowHandle, WindowFullscreenState fullscreenState );
/// <summary> /// Creates a new Window and shows it on the user's desktop. /// </summary> /// <param name="windowTitle">The title of the window (shown in the titlebar). Must not be null.</param> /// <param name="width">The width (or resolution X-scale) of the window.</param> /// <param name="height">The height (or resolution Y-scale) of the window.</param> /// <param name="fullscreenState">The initial fullscreen state of the window.</param> /// <param name="bufferingLevel">The number of back buffers to connect to the window. /// <see cref="MultibufferLevel.Double">Double</see> or <see cref="MultibufferLevel.Triple">triple</see> buffering can help with /// <see cref="RenderingModule.VSyncEnabled">vsync</see> issues at the cost of slightly greater memory usage.</param> /// <param name="windowIconFilePath">A file path of an icon to load for the window. May be null to use a default icon.</param> /// <exception cref="ArgumentException">Thrown if <paramref name="windowIconFilePath"/> does not exist or is an invalid /// path.</exception> public unsafe Window( string windowTitle, uint width = DEFAULT_WINDOW_WIDTH_PX, uint height = DEFAULT_WINDOW_HEIGHT_PX, WindowFullscreenState fullscreenState = WindowFullscreenState.NotFullscreen, MultibufferLevel bufferingLevel = MultibufferLevel.Single, string windowIconFilePath = null) { if (windowIconFilePath == null) { windowIconFilePath = Path.Combine(LosgapSystem.InstallationDirectory.FullName, DEFAULT_WINDOW_ICON); if (!File.Exists(windowIconFilePath)) { using (FileStream iconStream = File.Open(windowIconFilePath, FileMode.CreateNew)) { Properties.Resources.DefaultWindowIcon.Save(iconStream); } } } if (!IOUtils.IsValidFilePath(windowIconFilePath)) { throw new ArgumentException("'" + windowIconFilePath + "' is not a valid file path.", windowIconFilePath); } if (!File.Exists(windowIconFilePath)) { throw new ArgumentException("Icon file does not exist.", windowIconFilePath); } if (windowTitle == null) { throw new ArgumentNullException("windowTitle"); } var windowCreationResult = LosgapSystem.InvokeOnMaster(() => { WindowHandle outWindowHandle; InteropBool *outWindowClosureFlagPtr; InteropUtils.CallNative( NativeMethods.WindowFactory_CreateWindow, windowIconFilePath, RenderingModule.Device, ((uint)bufferingLevel) + 1U, (IntPtr)(&outWindowHandle), (IntPtr)(&outWindowClosureFlagPtr) ).ThrowOnFailure(); return(new { WindowHandle = outWindowHandle, WindowClosureFlagPtr = (IntPtr)outWindowClosureFlagPtr }); }); WindowHandle = windowCreationResult.WindowHandle; windowClosureFlagPtr = (InteropBool *)windowCreationResult.WindowClosureFlagPtr; lock (staticMutationLock) { openWindows.Add(this); } Title = windowTitle; FullscreenState = fullscreenState; SetResolution(width, height); AddViewport(ViewportAnchoring.TopLeft, Vector2.ZERO, Vector2.ONE); }
internal static void LoadFullscreenState() { try { string fullscreenStateData = File.ReadAllText(Path.Combine(projectLibraryPath, FullscreenStateFilename)); fullscreenState = SerializerUtility.Deserialize <FullscreenState>(fullscreenStateData); } catch (FileNotFoundException) { } catch (System.Exception e) { Debug.LogException(e); } if (fullscreenState.window == null) { fullscreenState.window = new List <WindowFullscreenState>(); } var allFullscreenStates = fullscreenState.window.ToArray(); WindowFullscreenState mainWindowFullscreenState = null; //Load types from assembly qualified names foreach (var state in allFullscreenStates) { try { state.ActualType = Type.GetType(state.actualTypeAssemblyQualifiedName); state.WindowType = Type.GetType(state.windowTypeAssemblyQualifiedName); } catch (System.Exception e) { if (LogNonFatalErrors) { Debug.LogException(e); } } } //Re-assign recreated window instances to their fullscreen states var allWins = Resources.FindObjectsOfTypeAll <EditorWindow>(); var unassignedFullscreenWins = new List <EditorWindow>(); foreach (var win in allWins) { if (win.GetShowMode() == EditorWindowExtensions.ShowMode.PopupMenu) { unassignedFullscreenWins.Add(win); } } foreach (var state in allFullscreenStates) { if (state.EditorWin != null) { unassignedFullscreenWins.Remove(state.EditorWin); } else if (state.WindowType == mainWindowType) { mainWindowFullscreenState = state; } else if (state.IsFullscreen) { foreach (var win in unassignedFullscreenWins) { var containerPosition = win.GetContainerPosition(); if (win.GetType() == state.ActualType && containerPosition.x == state.ContainerPosition.x && containerPosition.y == state.ContainerPosition.y) { state.EditorWin = win; unassignedFullscreenWins.Remove(win); break; } } } } loadedInitialState = true; //Find the window which was focused var focusedWindow = fullscreenState.window.Find(state => state.HasFocus == true); //Remake fullscreen windows foreach (var state in allFullscreenStates) { if (state.IsFullscreen) { if (state.EditorWin != null) { state.EditorWin.SetFullscreen(true, state.FullscreenAtPosition); } else if (state.WindowType != mainWindowType) { ToggleFullscreen(state.ActualType, true, state.FullscreenAtPosition, state.ShowTopToolbar, state.CreatedAtGameStart); } } } //Recreate the main window fullscreen state if (mainWindowFullscreenState != null && mainWindowFullscreenState.IsFullscreen) { var atPosition = mainWindowFullscreenState.FullscreenAtPosition; var showTopToolbar = mainWindowFullscreenState.ShowTopToolbar; if (mainWindowFullscreenState.containerWindow == null || mainWindowFullscreenState.originalContainerWindow == null) { fullscreenState.window.Remove(mainWindowFullscreenState); //Remove the old fullscreen state because the originalContainer needs to be reset } EditorMainWindow.SetFullscreen(true, showTopToolbar, atPosition); } //Remove fullscreen popup windows which don't have a fullscreen state foreach (var win in unassignedFullscreenWins) { if (win != null) { if (win.GetContainerWindow() != null) { win.Close(); } else { UnityEngine.Object.DestroyImmediate(win, true); } } } fullscreenState.CleanDeletedWindows(); //Bring any fullscreen window which is on top of the main window to the front. try { var windowOverMain = fullscreenState.window.Find(state => state.IsFullscreen && state.EditorWin != null && EditorDisplay.ClosestToPoint(state.FullscreenAtPosition).Bounds == EditorDisplay.ClosestToPoint(EditorMainWindow.position.center).Bounds); if (windowOverMain != null) { GiveFocusAndBringToFront(windowOverMain.EditorWin); } } catch { } //Refocus the window which was previously focused if (focusedWindow != null && focusedWindow.EditorWin != null) { GiveFocusAndBringToFront(focusedWindow.EditorWin); } //Toggle fullscreen for states which were queued up before load was complete foreach (var state in queuedStatesToToggleOnLoad) { ToggleFullscreen(state.ActualType, state.CloseOnExitFullscreen, state.FullscreenAtPosition, state.ShowTopToolbar, state.CreatedAtGameStart); } queuedStatesToToggleOnLoad.Clear(); if (RunOnNextLoadMethods != null) { RunOnNextLoadMethods.Invoke(); RunOnNextLoadMethods = null; } }