/// <summary>Focus a view.</summary> public static void FocusView(ScriptableObject guiView) { if (!guiView) { return; } // guiView.EnsureOfType(Types.GUIView); if (guiView.IsOfType(Types.GUIView)) { guiView.InvokeMethod("Focus"); } else { var vp = new ViewPyramid(guiView); var vc = vp.Container; var methodName = "Internal_BringLiveAfterCreation"; if (vc) { if (vc.HasMethod(methodName, new Type[] { typeof(bool), typeof(bool), typeof(bool) })) { // displayImmediately, setFocus, showMaximized vc.InvokeMethod(methodName, false, true, false); } else { // displayImmediately, setFocus vc.InvokeMethod(methodName, false, true); } } } }
/// <summary>Create a new instance and automatically assigns the window, view and container.</summary> public ViewPyramid(ScriptableObject viewOrWindow) { if (!viewOrWindow) { m_window = null; m_view = null; m_container = null; } else if (viewOrWindow.IsOfType(typeof(EditorWindow))) { m_window = viewOrWindow as EditorWindow; m_view = m_window.GetFieldValue <View>("m_Parent"); m_container = m_view.GetPropertyValue <ContainerWindow>("window"); } else if (viewOrWindow.IsOfType(Types.View)) { m_window = null; m_view = viewOrWindow; m_container = m_view.GetPropertyValue <ContainerWindow>("window"); } else if (viewOrWindow.IsOfType(Types.ContainerWindow)) { m_window = null; m_view = viewOrWindow.GetPropertyValue <ContainerWindow>("rootView"); m_container = viewOrWindow; } else { throw new ArgumentException("Param must be of type EditorWindow, View or ContainerWindow", "viewOrWindow"); } if (!m_window && m_view && m_view.IsOfType(Types.HostView)) { m_window = m_view.GetPropertyValue <EditorWindow>("actualView"); } m_windowInstanceID = m_window ? m_window.GetInstanceID() : 0; m_viewInstanceID = m_view ? m_view.GetInstanceID() : 0; m_containerInstanceID = m_container ? m_container.GetInstanceID() : 0; }
/// <summary>Returns a fullscreen rect</summary> /// <param name="mode">The mode that will be used to retrieve the rect.</param> /// <param name="targetWindow">The window that will be set fullscreen.</param> public static Rect GetFullscreenRect(RectSourceMode mode, ScriptableObject targetWindow = null) { if (targetWindow != null && !targetWindow.IsOfType(typeof(EditorWindow)) && !targetWindow.IsOfType(Types.View)) { throw new ArgumentException("Target window must be of type EditorWindow or View or null", "targetWindow"); } if (CustomRectCallback != null) { var rect = new Rect(); var shouldUse = CustomRectCallback(mode, out rect); if (shouldUse) { return(rect); } } switch (mode) { case RectSourceMode.MainDisplay: return(GetMainDisplayRect()); case RectSourceMode.WindowDisplay: if (targetWindow == null || !FullscreenUtility.IsWindows) { return(GetMainDisplayRect()); } var views = new ViewPyramid(targetWindow); var rect = views.Container.GetPropertyValue <Rect>("position"); return(GetDisplayBoundsAtPoint(rect.center)); case RectSourceMode.AtMousePosition: return(FullscreenUtility.IsWindows ? GetDisplayBoundsAtPoint(FullscreenUtility.MousePosition) : GetWorkAreaRect(true)); case RectSourceMode.Span: return(FullscreenUtility.IsWindows ? GetVirtualScreenBounds() : GetWorkAreaRect(true)); case RectSourceMode.Custom: return(GetCustomUserRect()); default: Logger.Warning("Invalid fullscreen mode, please fix this by changing the rect source mode in preferences."); return(new Rect(Vector2.zero, Vector2.one * 300f)); } }