Unity3D导出exe窗口参数调整培训

本文介绍如何使用Unity 3D (U3D) 对游戏窗口进行自定义设置,包括全屏、无边框窗口等多种显示模式,并通过C#代码实现窗口位置、大小和层级的调整。


 

下面我们开始今天。 我们学习目标:让U3D初学者可以更快速的掌握U3D技术,自行制作修改素材,可以独立完成2D、3D小规模游戏及网页游戏开发。

[csharp] view plaincopy

 

  1. using System;  

  2. using System.Runtime.InteropServices;  

  3. using UnityEngine;  

  4. public class WindowMod : MonoBehaviour  

  5. {  

  6.     public enum appStyle  

  7.     {  

  8.         FullScreen,  

  9.         WindowedFullScreen,  

  10.         Windowed,  

  11.         WindowedWithoutBorder  

  12.     }  

  13.     public enum zDepth  

  14.     {  

  15.         Normal,  

  16.         Top,  

  17.         TopMost  

  18.     }  

  19.     private const uint SWP_SHOWWINDOW = 64u;  

  20.     private const int GWL_STYLE = -16;  

  21.     private const int WS_BORDER = 1;  

  22.     private const int GWL_EXSTYLE = -20;  

  23.     private const int WS_CAPTION = 12582912;  

  24.     private const int WS_POPUP = 8388608;  

  25.     private const int SM_CXSCREEN = 0;  

  26.     private const int SM_CYSCREEN = 1;  

  27.     public WindowMod.appStyle AppWindowStyle = WindowMod.appStyle.WindowedFullScreen;  

  28.     public WindowMod.zDepth ScreenDepth;  

  29.     public int windowLeft = 10;  

  30.     public int windowTop = 10;  

  31.     public int windowWidth = 800;  

  32.     public int windowHeight = 600;  

  33.     private Rect screenPosition;  

  34.     private IntPtr HWND_TOP = new IntPtr(0);  

  35.     private IntPtr HWND_TOPMOST = new IntPtr(-1);  

  36.     private IntPtr HWND_NORMAL = new IntPtr(-2);  

  37.     private int Xscreen;  

  38.     private int Yscreen;  

  39.     private int i;  

  40.     [DllImport("user32.dll")]  

  41.     private static extern IntPtr GetForegroundWindow();  

  42.     [DllImport("user32.dll", CharSet = CharSet.Auto)]  

  43.     public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hPos, int x, int y, int cx, int cy, uint nflags);  

  44.     [DllImport("User32.dll")]  

  45.     private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  

  46.     [DllImport("User32.dll")]  

  47.     private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);  

  48.     [DllImport("User32.dll")]  

  49.     private static extern int GetWindowLong(IntPtr hWnd, int dwNewLong);  

  50.     [DllImport("User32.dll")]  

  51.     private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);  

  52.     [DllImport("user32.dll", CharSet = CharSet.Auto)]  

  53.     public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);  

  54.     [DllImport("user32.dll", CharSet = CharSet.Auto)]  

  55.     public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wP, IntPtr IP);  

  56.     [DllImport("user32.dll", CharSet = CharSet.Auto)]  

  57.     public static extern IntPtr SetParent(IntPtr hChild, IntPtr hParent);  

  58.     [DllImport("user32.dll", CharSet = CharSet.Auto)]  

  59.     public static extern IntPtr GetParent(IntPtr hChild);  

  60.     [DllImport("User32.dll")]  

  61.     public static extern IntPtr GetSystemMetrics(int nIndex);  

  62.     private void Start()  

  63.     {  

  64.         this.Xscreen = (int)WindowMod.GetSystemMetrics(0);  

  65.         this.Yscreen = (int)WindowMod.GetSystemMetrics(1);  

  66.         if (this.AppWindowStyle == WindowMod.appStyle.FullScreen)  

  67.         {  

  68.             Screen.SetResolution(this.Xscreen, this.Yscreen, true);  

  69.         }  

  70.         if (this.AppWindowStyle == WindowMod.appStyle.WindowedFullScreen)  

  71.         {  

  72.             Screen.SetResolution(this.Xscreen - 1, this.Yscreen - 1, false);  

  73.             this.screenPosition = new Rect(0f, 0f, (float)(this.Xscreen - 1), (float)(this.Yscreen - 1));  

  74.         }  

  75.         if (this.AppWindowStyle == WindowMod.appStyle.Windowed)  

  76.         {  

  77.             Screen.SetResolution(this.windowWidth, this.windowWidth, false);  

  78.         }  

  79.         if (this.AppWindowStyle == WindowMod.appStyle.WindowedWithoutBorder)  

  80.         {  

  81.             Screen.SetResolution(this.windowWidth, this.windowWidth, false);  

  82.             this.screenPosition = new Rect((float)this.windowLeft, (float)this.windowTop, (float)this.windowWidth, (float)this.windowWidth);  

  83.         }  

  84.     }  

  85.     private void Update()  

  86.     {  

  87.         if (this.i < 5)  

  88.         {  

  89.             if (this.AppWindowStyle == WindowMod.appStyle.WindowedFullScreen)  

  90.             {  

  91.                 WindowMod.SetWindowLong(WindowMod.GetForegroundWindow(), -16, 369164288);  

  92.                 if (this.ScreenDepth == WindowMod.zDepth.Normal)  

  93.                 {  

  94.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u);  

  95.                 }  

  96.                 if (this.ScreenDepth == WindowMod.zDepth.Top)  

  97.                 {  

  98.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u);  

  99.                 }  

  100.                 if (this.ScreenDepth == WindowMod.zDepth.TopMost)  

  101.                 {  

  102.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u);  

  103.                 }  

  104.                 WindowMod.ShowWindow(WindowMod.GetForegroundWindow(), 3);  

  105.             }  

  106.             if (this.AppWindowStyle == WindowMod.appStyle.Windowed)  

  107.             {  

  108.                 if (this.ScreenDepth == WindowMod.zDepth.Normal)  

  109.                 {  

  110.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, 0, 0, 0, 0, 3u);  

  111.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, 0, 0, 0, 0, 35u);  

  112.                 }  

  113.                 if (this.ScreenDepth == WindowMod.zDepth.Top)  

  114.                 {  

  115.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, 0, 0, 0, 0, 3u);  

  116.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOP, 0, 0, 0, 0, 35u);  

  117.                 }  

  118.                 if (this.ScreenDepth == WindowMod.zDepth.TopMost)  

  119.                 {  

  120.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, 0, 0, 0, 0, 3u);  

  121.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_TOPMOST, 0, 0, 0, 0, 35u);  

  122.                 }  

  123.             }  

  124.             if (this.AppWindowStyle == WindowMod.appStyle.WindowedWithoutBorder)  

  125.             {  

  126.                 WindowMod.SetWindowLong(WindowMod.GetForegroundWindow(), -16, 369164288);  

  127.                 if (this.ScreenDepth == WindowMod.zDepth.Normal)  

  128.                 {  

  129.                     WindowMod.SetWindowPos(WindowMod.GetForegroundWindow(), this.HWND_NORMAL, (int)this.screenPosition.x, (int)this.screenPosition.y, (int)this.screenPosition.width, (int)this.screenPosition.height, 64u);  

  130.                 }  

  131.                 if (this.ScreenDepth == WindowMod.zDepth.Top)  

  132.                 {  

  133. &


安全帽与口罩检测数据集 一、基础信息 数据集名称:安全帽与口罩检测数据集 图片数量: - 训练集:1690张图片 - 验证集:212张图片 - 测试集:211张图片 - 总计:2113张实际场景图片 分类类别: - HelmetHelmet:戴安全帽的人员,用于安全防护场景的检测。 - personwithmask:戴口罩的人员,适用于公共卫生监测。 - personwith_outmask:未戴口罩的人员,用于识别未遵守口罩佩戴规定的情况。 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 数据格式:JPEG/PNG图片,来源于实际监控和场景采集,细节清晰。 二、适用场景 工业安全监控系统开发: 数据集支持目标检测任务,帮助构建自动检测人员是否佩戴安全帽的AI模型,适用于建筑工地、工厂等环境,提升安全管理效率。 公共卫生管理应用: 集成至公共场所监控系统,实时监测口罩佩戴情况,为疫情防控提供自动化支持,辅助合规检查。 智能安防与合规检查: 用于企业和机构的自动化安全审计,减少人工干预,提高检查准确性和响应速度。 学术研究与AI创新: 支持计算机视觉目标检测领域的研究,适用于安全与健康相关的AI模型开发和论文发表。 三、数据集优势 精准标注与实用性: 每张图片均经过标注,边界框定位准确,类别定义清晰,确保模型训练的高效性和可靠性。 场景多样性与覆盖性: 包含安全帽和口罩相关类别,覆盖工业、公共场所以及多种实际环境,样本丰富,提升模型的泛化能力和适应性。 任务适配性强: 标注兼容主流深度学习框架(如YOLO),可直接用于目标检测任务,便于快速集成和部署。 实际应用价值突出: 专注于工业安全和公共健康领域,为自动化监控、合规管理以及疫情防护提供可靠数据支撑,具有较高的社会和经济价值。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值