/// <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);
                    }
                }
            }
        }
        internal void OpenView(Rect rect, ScriptableObject view)
        {
            if (!view)
            {
                throw new ArgumentNullException("view");
            }

            view.EnsureOfType(Types.View);

            if (FullscreenUtility.IsLinux)
            {
                throw new PlatformNotSupportedException("Linux does not support fullscreen from View class");
            }

            if (Fullscreen.GetFullscreenFromView(view))
            {
                Logger.Debug("Tried to fullscreen a view already in fullscreen");
                return;
            }

            BeforeOpening();

            var placeholder = CreateInstance <PlaceholderWindow>();

            m_src = new ViewPyramid(view);
            m_dst = CreateFullscreenViewPyramid(rect, placeholder);

            SwapViews(m_src.View, m_dst.View);
            Rect = rect;

            AfterOpening();
        }
Beispiel #3
0
        internal void OpenWindow(Rect rect, Type type, EditorWindow window = null, bool disposableWindow = false)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!type.IsOfType(typeof(EditorWindow)))
            {
                throw new ArgumentException("Type must be inherited from UnityEditor.EditorWindow", "type");
            }

            if (window is PlaceholderWindow)
            {
                FullscreenUtility.ShowFullscreenNotification(window, "Wanna fullscreen the placeholder?\nSorry, not possible");
                Logger.Debug("Tried to fullscreen a placeholder window");
                return;
            }

            if (Fullscreen.GetFullscreenFromView(window))
            {
                FullscreenUtility.ShowFullscreenNotification(window, "You can't fullscreen a window already in fullscreen");
                Logger.Debug("Tried to fullscreen a view already in fullscreen");
                return;
            }

            BeforeOpening();

            if (window)
            {
                m_src = new ViewPyramid(window);
            }

            var childWindow = window ?
                              (EditorWindow)CreateInstance <PlaceholderWindow>() :
                              (EditorWindow)CreateInstance(type); // Instantiate a new window for this fullscreen

            m_dst = CreateFullscreenViewPyramid(rect, childWindow);

            if (window) // We can't swap the src window if we didn't create a placeholder window
            {
                SwapWindows(m_src.Window, m_dst.Window);
            }

            Rect = rect;

            if (disposableWindow && childWindow is PlaceholderWindow)
            {
                childWindow.Close(); // Close the pyramid we created because disposable views are not restore later
                m_dst.Window = m_src.Window;
            }

            AfterOpening();
        }
        /// <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));
            }
        }
Beispiel #5
0
        /// <summary>Returns the parent <see cref="FullscreenContainer"/> for a given view or window, or null if it's not in fullscreen.</summary>
        /// <param name="rootView">Compare by the root view, otherwise compare by the container.</param>
        public static FullscreenContainer GetFullscreenFromView(ScriptableObject viewOrWindow, bool rootView = true)
        {
            if (!viewOrWindow)
            {
                return(null);
            }

            var pyramid = new ViewPyramid(viewOrWindow);

            return(Fullscreen
                   .GetAllFullscreen()
                   .FirstOrDefault(fullscreen => rootView ?
                                   fullscreen.ActualViewPyramid.View == pyramid.View :
                                   fullscreen.ActualViewPyramid.Container == pyramid.Container
                                   ));
        }
Beispiel #6
0
        // This should not be a static method, as static has no this
        // However, the 'this' in the method is unreliable and should be casted before using
        private void OnGUI()
        {
            var _this        = (object)this as SceneView;
            var vp           = new ViewPyramid(_this);
            var shouldRender = Fullscreen.GetFullscreenFromView(vp.Container, false); // Render if this window is in fullscreen

            _this.camera.gameObject.SetActive(shouldRender);

            if (shouldRender)
            {
                patcher.InvokeOriginal(_this); // This possibly throws a ExitGUIException
            }
            else
            {
                CustomOnGUI();
            }
        }
Beispiel #7
0
        internal bool IsPlaceholderVisible()
        {
            if (!(m_dst.Window is PlaceholderWindow))
            {
                return(false);
            }

            var pyramid = new ViewPyramid(m_dst.Window);

            if (!pyramid.View || !pyramid.View.IsOfType(Types.HostView))
            {
                return(false);
            }

            var actualView = pyramid.View.GetPropertyValue <View>("actualView");

            return(actualView == m_dst.Window);
        }