private static void Initialize() { initialized = true; try { scriptFileSubPath = GetMenuItemScriptFileRelativePath(); if (scriptFileSubPath == null) { return; } scriptFilePath = Application.dataPath + scriptFileSubPath; _settings = LoadSettings(); if (MenuItemScriptNeedsRefresh()) { _settings.SaveSettings(false); _settings.UpdateMenuItems(); } } catch (System.Exception e) { if (EWFDebugging.Enabled) { Debug.LogError("Settings failed to load."); Debug.LogException(e); EWFDebugging.LogError("Settings failed to load. " + e.Message); } } }
/// <summary> /// Closes all fullscreen editor windows. /// </summary> /// <returns>True if at least one fullscreen window was closed.</returns> public static bool CloseAllEditorFullscreenWindows() { bool closedAtLeastOneFullscreen = false; int numOfClosedFullscreens = 0; EWFDebugging.LogLine("Closing all fullscreen windows."); try { var allWinStates = EditorFullscreenState.fullscreenState.window.ToArray(); foreach (var win in allWinStates) { if (win.EditorWin != null && win.WindowType != EditorFullscreenState.MainWindowType) { if (win.IsFullscreen) { closedAtLeastOneFullscreen = true; if (EditorDisplay.ClosestToPoint(win.FullscreenAtPosition).Locked) { EditorFullscreenState.RunAfterDisplayNotLocked(win.FullscreenAtPosition, () => CloseAllEditorFullscreenWindows()); return(true); } if (settings.debugModeEnabled) { EWFDebugging.Log("Closing fullscreen for window, title: " + win.WindowTitle + " type: " + win.WindowType + " FullscreenAtPosition: " + win.FullscreenAtPosition + " Fullscreen in Bounds: " + win.ScreenBounds); } win.EditorWin.SetFullscreen(false); win.containerWindow = null; win.EditorWin = null; //Causes the fullscreen state to be removed in CleanDeletedWindows(); numOfClosedFullscreens++; } } } } catch (Exception e) { EWFDebugging.LogError("Error when closing all fullscreen windows: " + e.Message); } if (EditorMainWindow.IsFullscreen()) { closedAtLeastOneFullscreen = true; numOfClosedFullscreens++; EWFDebugging.Log("Closing main window fullscreen."); } EditorMainWindow.SetFullscreen(false); EditorFullscreenState.fullscreenState.CleanDeletedWindows(); EditorFullscreenState.TriggerFullscreenEvent(null, null, Vector2.zero, closedAtLeastOneFullscreen); EWFDebugging.LogLine("numOfClosedFullscreens: " + numOfClosedFullscreens); return(closedAtLeastOneFullscreen); }
internal static void TriggerOnResizedAll() { var containerWin = FindContainerWindow(); if (containerWin != null) { MethodInfo OnResizedC = FS.ContainerWindowType.GetMethod("OnResize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (OnResizedC != null) { OnResizedC.Invoke(containerWin, null); } else { EWFDebugging.LogWarning("ContainerWindow OnResize method doesn't exist."); } } }
#pragma warning restore 109 #else void OnGUI() #endif { var offsetToolbarHeight = EditorFullscreenState.sceneViewToolbarHeight + 1; var pos = this.basePosField; if (!toolbarVisible) { GUI.BeginGroup(new Rect(0, -offsetToolbarHeight, this.position.width, this.position.height + offsetToolbarHeight)); //Trick the base OnGUI into drawing the Scene View at full size by temporarily increasing the window height. pos.height += offsetToolbarHeight; this.basePosField = pos; } try { baseOnGUI.Invoke(this, null); } catch (ExitGUIException e) { throw e; } catch (TargetInvocationException e) { if (e.InnerException is ExitGUIException) { throw e.InnerException; } if (EWFDebugging.Enabled) { Debug.LogException(e); EWFDebugging.LogError(e.Message); } } if (!toolbarVisible) { //Reset the window height pos.height -= offsetToolbarHeight; this.basePosField = pos; GUI.EndGroup(); } }
public override void OnEnable() { var last = SceneView.lastActiveSceneView; var logEnabled = loggingEnabled; loggingEnabled = false; try { this.SetWindowTitle("Scene", true); base.OnEnable(); var sceneIconContent = EditorGUIUtility.IconContent(typeof(SceneView).ToString()); if (sceneIconContent != null) { this.titleContent.image = sceneIconContent.image; } } catch (System.Exception e) { loggingEnabled = logEnabled; if (EWFDebugging.Enabled) { Debug.LogException(e); EWFDebugging.LogError(e.Message); } } finally { loggingEnabled = logEnabled; } if (last != null) { //Overwite the contents of the new scene view state with the last scene view state. tookStateFromSceneView = last; #if UNITY_2019_1_OR_NEWER audioInitiallyEnabled = last.audioPlay; #else audioInitiallyEnabled = last.m_AudioPlay; #endif last.CopyStateTo(this); } }
internal static object[] GetAllChildViews() { try { var mainWindow = FindMainWindow(); PropertyInfo allChildren = FS.ViewType.GetProperty("allChildren", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); return((object[])allChildren.GetValue(mainWindow, null)); } catch (System.Exception e) { if (EWFDebugging.Enabled) { Debug.LogException(e); EWFDebugging.LogError(e.Message); } } return(null); }
private static SceneViewState SetSceneViewState(this SceneView sceneView, SceneViewState newState) { SceneViewState state = null; try { FieldInfo sceneViewState = typeof(SceneView).GetField("m_SceneViewState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); sceneViewState.SetValue(sceneView, newState); } catch (System.Exception e) { if (EWFDebugging.Enabled) { Debug.LogException(e); EWFDebugging.LogError(e.Message); } } return(state); }
new void OnDestroy() { //If the scene view which had its audio state taken still exists, re-enable the audio if it was originally enabled (Only one SceneView at a time can have audio enabled). #if UNITY_2019_1_OR_NEWER if (takeAudioState && tookStateFromSceneView != null && audioInitiallyEnabled && this.audioPlay) { tookStateFromSceneView.audioPlay = audioInitiallyEnabled; #else if (takeAudioState && tookStateFromSceneView != null && audioInitiallyEnabled && this.m_AudioPlay) { tookStateFromSceneView.m_AudioPlay = audioInitiallyEnabled; #endif base.OnDestroy(); try { MethodInfo onFocusMethod = typeof(SceneView).GetMethod("OnFocus", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (onFocusMethod != null) { onFocusMethod.Invoke(tookStateFromSceneView, null); } else { tookStateFromSceneView.RefreshAudioPlay(); } } catch (System.Exception e) { if (EWFDebugging.Enabled) { Debug.LogException(e); EWFDebugging.LogError(e.Message); } } } else { base.OnDestroy(); } }
/// <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); }
/// <summary> /// Triggers a Fullscreen Hotkey. /// </summary> /// <param name="keyCode">The key code of the hotkey to be triggered.</param> /// <param name="modifiers">The modifiers of the hotkey to be triggered.</param> /// <returns></returns> internal static bool TriggerFullscreenHotkey(KeyCode keyCode, EventModifiers modifiers) { if (EditorInput.performedHotkeyActionThisUpdate) { return(false); //Already triggered the hotkey } EWFDebugging.Begin(); bool setFullscreen = false; bool fullscreenHotkeyTriggered = true; var settings = EditorFullscreenSettings.settings; if (settings.debugModeEnabled) { EWFDebugging.LogLine("Triggered hotkey: " + EditorInput.GetKeysDownString(keyCode, modifiers) + " (key " + keyCode.ToKeyString() + " modifiers " + modifiers.ToString() + ")"); } EditorDisplay.ClearCachedDisplays(); EWFDebugging.StartTimer("Check hotkey and fullscreen"); if (CheckHotkeyTriggered(keyCode, modifiers, settings.closeAllFullscreenWindows)) { setFullscreen = CloseAllEditorFullscreenWindows(); //In this case setFullscreen is set to true if at least one fullscreen was closed. } else if (CheckHotkeyTriggered(keyCode, modifiers, settings.mainUnityWindow)) { setFullscreen = ToggleMainWindowFullscreen(); } else if (CheckHotkeyTriggered(keyCode, modifiers, settings.sceneWindow)) { setFullscreen = ToggleSceneViewFullscreen(); } else if (CheckHotkeyTriggered(keyCode, modifiers, settings.gameWindow)) { setFullscreen = ToggleGameViewFullscreen(false, settings.gameWindow.OptionID); } else if (CheckHotkeyTriggered(keyCode, modifiers, settings.currentlyFocusedWindow)) { setFullscreen = ToggleFocusedWindowFullscreen(); } else if (CheckHotkeyTriggered(keyCode, modifiers, settings.windowUnderCursor)) { setFullscreen = ToggleWindowUnderCursorFullscreen(); } else if (CheckHotkeyTriggered(keyCode, modifiers, settings.toggleTopToolbar)) { ToggleTopToolbar(); } else { fullscreenHotkeyTriggered = false; //Check if a custom window hotkey is triggered if (settings.customWindows != null) { for (int i = 0; i < settings.customWindows.Count; i++) { if (CheckHotkeyTriggered(keyCode, modifiers, settings.customWindows[i])) { if (settings.customWindows[i].isGameView) { setFullscreen = ToggleGameViewFullscreen(false, settings.customWindows[i].OptionID); } else { setFullscreen = EditorFullscreenState.ToggleFullscreenUsingOptions(settings.customWindows[i].WindowType, settings.customWindows[i]); } fullscreenHotkeyTriggered = true; break; } } } } EWFDebugging.LogTime("Check hotkey and fullscreen"); if (fullscreenHotkeyTriggered) { triggeredHotkey = null; //Reset the triggered hotkey after fullscreen is toggled. } if (FullscreenHotkeyEventHandler != null && fullscreenHotkeyTriggered) { FullscreenHotkeyEventHandler.Invoke(keyCode, modifiers, setFullscreen); } EWFDebugging.LogLine("fullscreenHotkeyTriggered: " + fullscreenHotkeyTriggered + ", setFullscreen: " + setFullscreen); if (fullscreenHotkeyTriggered) { EWFDebugging.PrintLog(); EditorInput.performedHotkeyActionThisUpdate = true; } return(fullscreenHotkeyTriggered); }
public static void SetFullscreen(bool fullscreen, bool showTopToolbar, Vector2 fullscreenAtPosition, bool disableUpdatePrePos) { var fullscreenState = GetWindowFullscreenState(); var fullscreenOnDisplay = EditorDisplay.ClosestToPoint(fullscreenAtPosition); var screenBounds = fullscreenOnDisplay.Bounds; #if UNITY_EDITOR_OSX if (fullscreenOnDisplay.Locked) { FS.RunAfterDisplayNotLocked(fullscreenAtPosition, () => SetFullscreen(fullscreen, showTopToolbar, fullscreenAtPosition, disableUpdatePrePos)); return; } #endif var originallyFocusedEditorWin = EditorWindow.focusedWindow; var originallyFocusedEditorWinType = originallyFocusedEditorWin == null ? null : originallyFocusedEditorWin.GetType(); object mainWindow = null; #if UNITY_EDITOR_OSX bool wasFullscreen = SystemDisplay.MainWindowIsFullscreen(); //If toggling the top toolbar, don't update pre positions. bool updatePrePos = fullscreen && !wasFullscreen && !disableUpdatePrePos; windowController = IntPtr.Zero; if (fullscreen) { fullscreenState.ScreenBounds = screenBounds; fullscreenState.FullscreenAtPosition = fullscreenAtPosition; } if (updatePrePos) { fullscreenState.PreFullscreenPosition = position; fullscreenState.PreFullscreenMinSize = minSize; fullscreenState.PreFullscreenMaxSize = maxSize; } var prePos = fullscreenState.PreFullscreenPosition; if (prePos.width < 100 || prePos.height < 100 || prePos.width < fullscreenState.PreFullscreenMinSize.x || prePos.height < fullscreenState.PreFullscreenMinSize.y) { prePos = new Rect(prePos.x, prePos.y, Mathf.Max(fullscreenState.PreFullscreenMinSize.x, 300), Mathf.Max(fullscreenState.PreFullscreenMinSize.y, 300)); //Make sure size is valid } if (fullscreen && !screenBounds.Contains(position.center)) { if (wasFullscreen) { //Exit fullscreen because we are fullscreen on another screen fullscreen = false; } else { //Move to the correct screen SystemDisplay.SetMainWindowPosition((int)screenBounds.xMin, (int)screenBounds.yMin, (int)screenBounds.width, (int)screenBounds.height); } } if (fullscreen != wasFullscreen) { windowController = SystemDisplay.ToggleFullscreenMainWindow((int)prePos.xMin, (int)prePos.yMin, (int)prePos.width, (int)prePos.height); if (!fullscreen) { if (fullscreenState.ScreenBounds.Contains(prePos)) { position = prePos; //Setting the position here first (even though still haven't finished exiting fullscreen) updates the docked window sizes so the shrinking animation is smoother. } else { var intermediatePos = fullscreenState.PreFullscreenPosition.CenterRectInBounds(fullscreenState.ScreenBounds); position = intermediatePos; //Can't move screen yet because still fullscreen, so use an intermediate pos. } //Restore position once the fullscreen has finished exiting if (windowController != IntPtr.Zero) { fullscreenOnDisplay.Locked = true; EditorApplication.update += CheckForFinishExitingFullscreen; numChecksForFinishExiting = 0; } } else { fullscreenOnDisplay.Locked = true; FS.RunAfter(() => { return(false); }, () => { fullscreenOnDisplay.Locked = false; fullscreenState.currentlyRestoringFromState = false; FS.SaveFullscreenState(); }, 50, true); } } fullscreenState.IsFullscreen = fullscreen; FS.SaveFullscreenState(); #else bool wasFullscreen = fullscreenState.IsFullscreen; fullscreenState.ShowTopToolbar = showTopToolbar; fullscreenState.originalContainerWindow = (ScriptableObject)FindOriginalContainerWindow(); fullscreenState.containerWindow = (ScriptableObject)FindContainerWindow(); mainWindow = FindMainWindow(); bool inOriginalContainer = fullscreenState.containerWindow == fullscreenState.originalContainerWindow; #if UNITY_2018_2_OR_NEWER var pixelsPerPoint = GetPixelsPerPointAtPosition(fullscreenAtPosition); screenBounds.width /= pixelsPerPoint; screenBounds.height /= pixelsPerPoint; #endif if (fullscreen) { fullscreenState.ScreenBounds = screenBounds; fullscreenState.FullscreenAtPosition = fullscreenAtPosition; if (!wasFullscreen) { var wasMaximized = maximized; if (wasMaximized) { ToggleMaximize(); } fullscreenState.PreFullscreenPosition = position; fullscreenState.PreFullscreenMinSize = minSize; fullscreenState.PreFullscreenMaxSize = maxSize; fullscreenState.PreFullscreenMaximized = wasMaximized; if (inOriginalContainer) { SystemDisplay.SaveMainWindowStyleInState(fullscreenState); } } } if (fullscreen && !showTopToolbar) { object fsContainerWindow; if (inOriginalContainer) { fsContainerWindow = ScriptableObject.CreateInstance(FS.ContainerWindowType); } else { fsContainerWindow = fullscreenState.containerWindow; } //Put the main view into the fullscreen container window containerMainView.SetValue(fsContainerWindow, mainWindow, null); inOriginalContainer = false; containerPosition.SetValue(fsContainerWindow, screenBounds, null); if (containerShow.GetParameters().Length == 3) { containerShow.Invoke(fsContainerWindow, new object[] { 3, false, true }); } else if (containerShow.GetParameters().Length == 4) { containerShow.Invoke(fsContainerWindow, new object[] { 3, false, true, true }); //4 parameters since Unity 2018 } SetMinMaxSizes(screenBounds.size, screenBounds.size); containerPosition.SetValue(fsContainerWindow, screenBounds, null); MethodInfo displayAllViews = FS.ContainerWindowType.GetMethod("DisplayAllViews", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new System.Type[] { }, null); displayAllViews.Invoke(fsContainerWindow, null); fullscreenState.containerWindow = (ScriptableObject)fsContainerWindow; fullscreenState.IsFullscreen = true; } else { if (fullscreenState.EditorWin != null) { fullscreenState.EditorWin.Close(); } if (!inOriginalContainer) { //Reset main view back to original container view containerMainViewField.SetValue(fullscreenState.originalContainerWindow, null); containerMainView.SetValue(fullscreenState.originalContainerWindow, mainWindow, null); try { containerMainViewField.SetValue(fullscreenState.containerWindow, null); containerClose.Invoke(fullscreenState.containerWindow, null); } catch (System.Exception e) { if (EWFDebugging.Enabled) { Debug.LogException(e); EWFDebugging.LogError(e.Message); } } fullscreenState.containerWindow = fullscreenState.originalContainerWindow; fullscreenState.IsFullscreen = false; inOriginalContainer = true; } if (fullscreen) { //Set fullscreen with toolbar var newPos = screenBounds; newPos.yMin += topToolbarHeight; position = newPos; SetMinMaxSizes(newPos.size, newPos.size); position = newPos; if (position.x != newPos.x) { //Position didn't set correctly, so must be maximized fullscreenState.PreFullscreenMaximized = true; ToggleMaximize(); position = newPos; } fullscreenState.IsFullscreen = true; } } if (!fullscreen && inOriginalContainer && wasFullscreen) { //Reset position var prePos = fullscreenState.PreFullscreenPosition; position = prePos; fullscreenState.IsFullscreen = false; position = fullscreenState.PreFullscreenPosition; SetMinMaxSizes(fullscreenState.PreFullscreenMinSize, fullscreenState.PreFullscreenMaxSize); position = fullscreenState.PreFullscreenPosition; PropertyInfo pos = FS.ViewType.GetProperty("position", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); pos.SetValue(FindMainWindow(), fullscreenState.PreFullscreenPosition, null); fullscreenState.IsFullscreen = false; SystemDisplay.LoadMainWindowStyleInState(fullscreenState, true); TriggerOnResizedAll(); Focus(); position = fullscreenState.PreFullscreenPosition; //Reset position position = fullscreenState.PreFullscreenPosition; if (fullscreenState.PreFullscreenMaximized != maximized) { ToggleMaximize(); } } fullscreenState.currentlyRestoringFromState = false; FS.SaveFullscreenState(); #endif //All platforms FS.TriggerFullscreenEvent(mainWindow, FS.MainWindowType, fullscreenAtPosition, fullscreen); if (EditorWindow.focusedWindow == null) { if (originallyFocusedEditorWin != null) { originallyFocusedEditorWin.Focus(); } else if (originallyFocusedEditorWinType != null) { EditorWindow.FocusWindowIfItsOpen(originallyFocusedEditorWinType); } } }