コード例 #1
0
ファイル: ScreenHelpers.cs プロジェクト: emilppp/kex
        /// <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));
        }
コード例 #2
0
ファイル: ScreenHelpers.cs プロジェクト: emilppp/kex
        /// <summary>
        /// Maps from logical pixels to physical desktop pixels.
        /// </summary>
        /// <param name="rect">Rectangle to be transformed.</param>
        /// <returns>Transformed rectangle.</returns>
        protected virtual Rect LogicalToPhysical(Rect rect)
        {
            var topLeft = new Win32Helpers.POINT {
                x = (int)rect.x, y = (int)rect.y
            };

            Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref topLeft);

            var bottomRight = new Win32Helpers.POINT {
                x = (int)(rect.x + rect.width), y = (int)(rect.y + rect.height)
            };

            Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref bottomRight);

            return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y));
        }
コード例 #3
0
ファイル: WindowHelpers.cs プロジェクト: emilppp/kex
        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);
        }
コード例 #4
0
ファイル: WindowHelpers.cs プロジェクト: emilppp/kex
 private static bool IsMainWindow(IntPtr hwnd)
 {
     return((Win32Helpers.GetWindow(hwnd, Win32Helpers.GW_OWNER) == IntPtr.Zero) && Win32Helpers.IsWindowVisible(hwnd));
 }
コード例 #5
0
ファイル: WindowHelpers.cs プロジェクト: emilppp/kex
        /// <summary>
        /// Shows the current window.
        /// </summary>
        public static void ShowCurrentWindow()
        {
            IntPtr hwnd = FindWindowWithThreadProcessId(Process.GetCurrentProcess().Id);

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