Untiy的PC端强制全屏、去掉标题栏

在之前的公司做的项目中,客户经常要求将程序设置成全屏。Unity自己打包设置中虽然也有全屏的设置,但是效果不是很好,而且不能强制置顶,经常被其它应用程序遮盖。所以我在这里安利一个Unity强制全屏的插件,可以非常简单地解决这个问题…

 

使用步骤

1.将插件解压到项目中,如图所示:

2.将Prafabs文件夹中的WindowMod预制体拖入场景中,如图所示:

3.WindowMod.cs脚本代码如下所示:

using System; using System.Runtime.InteropServices; using UnityEngine; public class WindowMod : MonoBehaviour { public enum appStyle { FullScreen, WindowedFullScreen, Windowed, WindowedWithoutBorder } public enum zDepth { Normal, Top, TopMost } private const uint SWP_SHOWWINDOW = 64u; private const int GWL_STYLE = -16; private const int WS_BORDER = 1; private const int GWL_EXSTYLE = -20; private const int WS_CAPTION = 12582912; private const int WS_POPUP = 8388608; private const int SM_CXSCREEN = 0; private const int SM_CYSCREEN = 1; public WindowMod.appStyle AppWindowStyle = WindowMod.appStyle.WindowedFullScreen; public WindowMod.zDepth ScreenDepth; private int windowLeft = 0; private int windowTop = 0; private int windowWidth = 1008; private int windowHeight = 567; private Rect screenPosition; private IntPtr HWND_TOP = new IntPtr(0); private IntPtr HWND_TOPMOST = new IntPtr(-1); private IntPtr HWND_NORMAL = new IntPtr(-2); private int Xscreen; private int Yscreen; private int i; [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hPos, int x, int y, int cx, int cy, uint nflags); [DllImport("User32.dll")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [DllImport("User32.dll")] private static extern int GetWindowLong(IntPtr hWnd, int dwNewLong); [DllImport("User32.dll")] private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wP, IntPtr IP); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SetParent(IntPtr hChild, IntPtr hParent); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr GetParent(IntPtr hChild); [DllImport("User32.dll")] public static extern IntPtr GetSystemMetrics(int nIndex); private void Start() { this.Xscreen = (int)WindowMod.GetSystemMetrics(0); this.Yscreen = (int)WindowMod.GetSystemMetrics(1); if (this.AppWindowStyle == WindowMod.appStyle.FullScreen) { Screen.SetResolution(this.Xscreen, this.Yscreen, true); } if (this.AppWindowStyle == WindowMod.appStyle.WindowedFullScreen) { Screen.SetResolution(this.Xscreen - 1, this.Yscreen - 1, false); this.screenPosition = new Rect(0f, 0f, (float)(this.Xscreen - 1), (float)(this.Yscreen - 1)); } if (this.AppWindowStyle == WindowMod.appStyle.Windowed) { Screen.SetResolution(this.windowWidth, this.windowWidth, false); } if (this.AppWindowStyle == WindowMod.appStyle.WindowedWithoutBorder) { Screen.SetResolution(this.windowWidth, this.windowWidth, false); this.screenPosition = new Rect((float)this.windowLeft, (float)this.windowTop, (float)this.windowWidth, (float)this.windowHeight); //this.screenPosition = new Rect(300,180,(float)this.windowWidth,(float)this.windowHeight); } } private void Update() { if (this.i < 5) { if (this.AppWindowStyle == WindowMod.appStyle.WindowedFullScreen) { WindowMod.SetWindowLong(WindowMod.GetForegroundWindow(), -16, 369164288); if (this.ScreenDepth == WindowMod.zDepth.Normal) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u); } if (this.ScreenDepth == WindowMod.zDepth.Top) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u); } if (this.ScreenDepth == WindowMod.zDepth.TopMost) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u); } WindowMod.ShowWindow(WindowMod.GetForegroundWindow(), 3); } if (this.AppWindowStyle == WindowMod.appStyle.Windowed) { if (this.ScreenDepth == WindowMod.zDepth.Normal) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, 0, 0, 0, 0, 3u); WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, 0, 0, 0, 0, 35u); } if (this.ScreenDepth == WindowMod.zDepth.Top) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, 0, 0, 0, 0, 3u); WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, 0, 0, 0, 0, 35u); } if (this.ScreenDepth == WindowMod.zDepth.TopMost) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, 0, 0, 0, 0, 3u); WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, 0, 0, 0, 0, 35u); } } if (this.AppWindowStyle == WindowMod.appStyle.WindowedWithoutBorder) { WindowMod.SetWindowLong(WindowMod.GetForegroundWindow(), -16, 369164288); if (this.ScreenDepth == WindowMod.zDepth.Normal) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u); } if (this.ScreenDepth == WindowMod.zDepth.Top) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u); } if (this.ScreenDepth == WindowMod.zDepth.TopMost) { WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u); } } } this.i++; } }

 

4.通过修改windowWidth与windowHeight参数修改打包程序的分辨率,如下图所示:

步骤4

5.WindowMod组件上WindowMod.cs设置如图所示:

步骤5

6.打包,打开程序,发现程序已经强制全屏并去掉标题栏,而且程序已置顶,如下图所示:

步骤6

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我了解了。为了使用playWright测试淘宝PC登录页,你需要先安装playWright库,并在Python中导入相关模块。然后,你可以编写代码访问淘宝PC登录页面、输入用户名和密码等信息,最后验证是否成功登录。下面是一个基本的示例代码: ```python import asyncio from playwright.async_api import Playwright, async_playwright async def login_taobao(page): # 访问淘宝PC登录页面 await page.goto('https://login.taobao.com/member/login.jhtml') # 找到并输入用户名 await page.type('#TPL_username_1', 'your_username') # 找到并输入密码 await page.type('#TPL_password_1', 'your_password') # 点击登录按钮 await page.click('#J_SubmitStatic') # 等待登录成功页面加载完成,例如通过检查某个元素是否存在来判断是否登录成功 await page.wait_for_selector('.site-nav-username') async def main(playwright: Playwright) -> None: # 启动浏览器 browser = await playwright.chromium.launch(headless=False) # 打开新页面 page = await browser.new_page() # 登录淘宝 await login_taobao(page) # 关闭浏览器 await browser.close() if __name__ == '__main__': with async_playwright() as playwright: asyncio.get_event_loop().run_until_complete(main(playwright)) ``` 你需要将此代码保存到一个Python文件中,将其中的 `your_username` 和 `your_password` 修改为你的淘宝账号和密码,然后运行该文件即可执行测试。 需要注意的是,由于Network的请求可能会发生变化,如果需要在不同的时间段反复测试,需要手动替换Network请求。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值