Пример #1
0
        /// <summary>
        /// Gets the eye tracked monitor's screen bounds on the Virtual Screen.
        /// </summary>
        /// <returns>Rect populated with upper-left corner location (x,y), and
        /// screen size (width, height) in pixels on the Virtual Screen.</returns>
        public Rect GetMonitorScreenBounds()
        {
            var monitorHandle = Win32Helpers.MonitorFromWindow(Hwnd, Win32Helpers.MONITOR_DEFAULTTONEAREST);
            var monitorInfo   = new Win32Helpers.MONITORINFO();

            monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);

            Win32Helpers.GetMonitorInfo(monitorHandle, ref monitorInfo);
            var rc = monitorInfo.rcMonitor;

            return(new Rect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top));
        }
Пример #2
0
        /// <summary>
        /// Gets the Game View window's bottom right corner Position.
        /// </summary>
        /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks>
        protected virtual Vector2 GetWindowBottomRight()
        {
            var clientRect = new Win32Helpers.RECT();

            Win32Helpers.GetClientRect(Hwnd, ref clientRect);

            var bottomRight = new Win32Helpers.POINT {
                x = clientRect.right, y = clientRect.bottom
            };

            Win32Helpers.ClientToScreen(Hwnd, ref bottomRight);

            return(new Vector2(bottomRight.x, bottomRight.y));
        }
 private static bool IsMainWindow(IntPtr hwnd)
 {
     return((Win32Helpers.GetWindow(hwnd, Win32Helpers.GW_OWNER) == IntPtr.Zero) && Win32Helpers.IsWindowVisible(hwnd));
 }
        internal static IntPtr GetGameViewWindowHandle(int processId)
        {
            const string GameViewCaption         = "UnityEditor.GameView";
            const string UnityContainerClassName = "UnityContainerWndClass";

            var window = new IntPtr();

            Win32Helpers.EnumWindows(delegate(IntPtr hWnd, IntPtr lParam)
            {
                if (!Win32Helpers.IsWindowVisible(hWnd))
                {
                    return(true);
                }

                var windowProcessId = 0;
                Win32Helpers.GetWindowThreadProcessId(hWnd, out windowProcessId);

                if (windowProcessId == processId)
                {
                    StringBuilder builder = new StringBuilder(256);
                    Win32Helpers.GetClassName(hWnd, builder, 256);

                    if (builder.ToString() == UnityContainerClassName)
                    {
                        //Ok, we found one of our containers, let's try to find the game view handle among the children
                        Win32Helpers.EnumChildWindows(hWnd, delegate(IntPtr childHwnd, IntPtr childParam)
                        {
                            if (!Win32Helpers.IsWindowVisible(childHwnd))
                            {
                                return(true);
                            }

                            int childLength = Win32Helpers.GetWindowTextLength(childHwnd);
                            if (childLength == 0)
                            {
                                return(true);
                            }

                            StringBuilder childBuilder = new StringBuilder(childLength);
                            Win32Helpers.GetWindowText(childHwnd, childBuilder, childLength + 1);

                            if (childBuilder.ToString() == GameViewCaption)
                            {
                                //Found it!
                                window = childHwnd;
                                return(false);
                            }

                            return(true);
                        },
                                                      IntPtr.Zero);
                    }
                }

                return(true);
            }, IntPtr.Zero);

            if (window.Equals(IntPtr.Zero))
            {
                UnityEngine.Debug.LogError("Could not find game view!");
            }

            return(window);
        }
        /// <summary>
        /// Shows the current window.
        /// </summary>
        public static void ShowCurrentWindow()
        {
            IntPtr hwnd = FindWindowWithThreadProcessId(Process.GetCurrentProcess().Id);

            Win32Helpers.ShowWindowAsync(hwnd, Win32Helpers.SW_SHOWDEFAULT);
        }