Unity无边框PC 包
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//无边窗口
private int winWidth;// 窗口宽度
private int winHeight;// 窗口高度
private int winPosX;// 窗口左上角x
private int winPosY;// 窗口左上角y
const int GWL_STYLE = -16;
const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
const int WS_POPUP = 0x800000;
const uint SWP_SHOWWINDOW = 0x0040;
IEnumerator WindowWithoutFrame()
{//默认分辨率无边框显示(可以自由根据winWidth和winHeight的值调整无边框的分辨率)
winWidth = 960;
winHeight = 540;
//显示器支持的所有分辨率
int i = Screen.resolutions.Length;
int resWidth = Screen.resolutions[i - 1].width;
int resHeight = Screen.resolutions[i - 1].height;
winPosX = resWidth / 2 - winWidth / 2;
winPosY = resHeight / 2 - winHeight / 2;
IntPtr hwnd = FindWindow(null, "WindowName");
yield return new WaitForSeconds(0.1f);
SetWindowLong(hwnd, GWL_STYLE, WS_POPUP);
bool result = SetWindowPos(hwnd, 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);
}