`
wgcode
  • 浏览: 576985 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Unity3d 去掉exe版本的边框

阅读更多
[csharp] view plaincopy
 
  1. using UnityEngine;  
  2. using System.Collections;  
  3. using System.Runtime.InteropServices;  
  4. using System;  
  5.   
  6. public class Test : MonoBehaviour  
  7. {   
  8.     /// <summary>  
  9.     /// 窗口宽度  
  10.     /// </summary>  
  11.     public int winWidth;  
  12.     /// <summary>  
  13.     /// 窗口高度  
  14.     /// </summary>  
  15.     public int winHeight;  
  16.     /// <summary>  
  17.     /// 窗口左上角x  
  18.     /// </summary>  
  19.     public int winPosX;  
  20.     /// <summary>  
  21.     /// 窗口左上角y  
  22.     /// </summary>  
  23.     public int winPosY;  
  24.   
  25.     [DllImport("user32.dll")]  
  26.     static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);  
  27.     [DllImport("user32.dll")]  
  28.     static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);  
  29.     [DllImport("user32.dll")]  
  30.     static extern IntPtr GetForegroundWindow();  
  31.   
  32.     const uint SWP_SHOWWINDOW = 0x0040;  
  33.     const int GWL_STYLE = -16;  
  34.     const int WS_BORDER = 1;  
  35.     const int WS_POPUP = 0x800000;  
  36.   
  37.     // Use this for initialization  
  38.     void Start()  
  39.     {  
  40.         winWidth = 610;  
  41.         winHeight = 350;  
  42.         //显示器支持的所有分辨率  
  43.         int i = Screen.resolutions.Length;  
  44.   
  45.         int resWidth = Screen.resolutions[i - 1].width;  
  46.         int resHeight = Screen.resolutions[i - 1].height;  
  47.   
  48.         winPosX = resWidth / 2 - winWidth / 2;  
  49.         winPosY = resHeight / 2 - winHeight / 2;  
  50.   
  51.         SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);  
  52.         bool result = SetWindowPos(GetForegroundWindow(), 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);  
  53.   
  54.     }  
  55. }  

原文地址点击这里

 

测试发现GUI坐标偏差,修改如下

 

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. using UnityEngine;  
  2. using System.Collections;  
  3. using System.Runtime.InteropServices;  
  4. using System;  
  5.   
  6. public class Test : MonoBehaviour  
  7. {  
  8.     /// <summary>  
  9.     /// 窗口宽度  
  10.     /// </summary>  
  11.     public int winWidth;  
  12.     /// <summary>  
  13.     /// 窗口高度  
  14.     /// </summary>  
  15.     public int winHeight;  
  16.     /// <summary>  
  17.     /// 窗口左上角x  
  18.     /// </summary>  
  19.     public int winPosX;  
  20.     /// <summary>  
  21.     /// 窗口左上角y  
  22.     /// </summary>  
  23.     public int winPosY;  
  24.   
  25.     [DllImport("user32.dll")]  
  26.     static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);  
  27.     [DllImport("user32.dll")]  
  28.     static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);  
  29.     [DllImport("user32.dll")]  
  30.     static extern IntPtr GetForegroundWindow();  
  31.   
  32.     [DllImport("User32.dll", EntryPoint = "GetSystemMetrics")]  
  33.     public static extern IntPtr GetSystemMetrics(int nIndex);  
  34.   
  35.     const int SM_CXSCREEN = 0x00000000;  
  36.     const int SM_CYSCREEN = 0x00000001;  
  37.   
  38.     const uint SWP_SHOWWINDOW = 0x0040;  
  39.     const int GWL_STYLE = -16;  
  40.     const int WS_BORDER = 1;  
  41.     const int WS_POPUP = 0x800000;  
  42.   
  43.     public GUIText t;  
  44.   
  45.     // Use this for initialization  
  46.     void Start()  
  47.     {  
  48.         winWidth = 610;  
  49.         winHeight = 350;  
  50.         //当前屏幕分辨率  
  51.         int resWidth = (int)GetSystemMetrics(SM_CXSCREEN);  
  52.         int resHeight = (int)GetSystemMetrics(SM_CYSCREEN);  
  53.   
  54.         winPosX = resWidth / 2 - winWidth / 2;  
  55.         winPosY = resHeight / 2 - winHeight / 2 -1;  
  56.   
  57.         SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);  
  58.         //测试发现左下角坐标为(0,1),修改如下  
  59.         bool result = SetWindowPos(GetForegroundWindow(), 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);  
  60.         //bool result = SetWindowPos(GetForegroundWindow(), 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);  
  61.           
  62.     }  
  63.   
  64.     void OnGUI()  
  65.     {  
  66.         if (Input.GetMouseButtonDown(0))  
  67.         {  
  68.             t.text = "X:"+Input.mousePosition.x + " Y:" + Input.mousePosition.y;  
  69.         }  
  70.     }  
  71. }  

 

分享到:
评论

相关推荐

    Unity导exe 去掉程序边框

    Unity导exe 去掉程序边框

    unity3d outline shader 边框 着色器

    unity3d outline shader 边框 着色器

    2023新Unity打包exe,透明,穿透最新解决方案

    Unity打包exe去边框,置顶,透明,透明穿透解决方案,19后版本Edit——ProjectSettings——Player——ResolutionandPresentation——UseDXGIFlipModelSwapchainforD3D11选项设为false. 脚本随便挂,摄像机的Clear Flags...

    unity3d 游戏物体 轮廓

    Unity3D中物体的轮廓显示,此处分为薄边和厚边两种。无入侵式实现。

    Unity3D实现描边框效果

    主要为大家详细介绍了Unity3D实现描边框效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    Unity3d窗体透明

    这是已经设置好的Unity文件,只需要把脚本 (TransparentWindow) 放入摄像机 (Main Camera) 中加入材质球点击导出 (Build) 运行一下就行了

    Unity3D 模型的几种线框 shader

    Unity3D 模型的几种线框 shader。 模型的几种线框shader。 模型的几种线框shader,需要线框化模型的时候使用,比如选中模型线框化,只能看到模型线,看不到三角面 Unity3d Shader

    Unity3D 界面插件 NGUI基础带图详解

    Unity3D 界面插件 NGUI基础学习,带图详解 1.创建你的界面 2.精灵Sprite 3.SlideSprite 4.拼贴精灵TiledSprite 5.标签 6.按钮 7.滑块 8.复选框 9.输入框 10.2D转3D

    Unity去除边框并置顶程序

    可以让build出来的程序无边框运行并置顶,并且默认隐藏鼠标,可以自适应屏幕,也可以在双屏模式下延伸屏幕,可以置顶也可以置底,拖入改参数即可,变量名已经改成中文方便理解

    炫酷的Unity3d UI 自定义圆角面板 插件

    炫酷的Unity3d UI 自定义圆角面板 插件 Unity UI 圆角面板 - 这是一个简单而实用的Unity资产,可在Unity中创建圆角面板。使用此资源,您可以轻松创建许多形式的Unity ui按钮图片等面板,赶快试试吧! 优点: - ...

    unity3d 素材包(粒子特效的)

    unity3d 粒子特效包,主要有的效果是雨,雪,烟雾等特效制作

    unity 制作圆角图片添加边框的实用Demo

    圆角图片边框Shader(Unity Package) 这个Unity Shader包提供了一种简单而有效的方法来为图片添加圆角和边框效果。通过使用这个Shader,你可以轻松地为任何2D图像创建平滑的圆角效果,并在需要时添加自定义颜色和...

    去掉下拉框的边框

    去除下拉框的边框,包括下拉的按钮,内有demo

    Unity3D窗口设置

    自己总结出来的unity3d发布窗口设置,可以指定位置,大小,窗口式样(边框,标题,按钮,滚动条,隐藏,激活,置顶,置底等)。 下载之后直接把脚本挂物体上就可使用。 如果有不明白的请打开脚本,脚本里面的注释...

    按钮边框流光特效

    按钮边框流光特效

    Unity3D点选物体、框选物体、绘制外边框

    本资源实现了以下需求: 点选物体:点击物体,可以选中物体,按住 Ctrl... 框选物体:拖拽鼠标,屏幕上会出现滑动框,滑动框内的物体会被选中,选中的物体设置为红色。 绘制外边框:给选中的物体绘制外边框(选中框)。

    dialog去除边框代码

    dialog去除边框代码

    去除边框和分隔线

    去除边框和分隔线

    Qt去掉标题栏添加边框阴影

    基于Qt5的去掉标题栏之后添加边框阴影的解决方案。 四种解决方法: 1. 如果是Windows平台,那么可以调用Windows相关API。 2. 使用Qt的QGraphicsDropShadowEffect类来实现。 3. 使用Qt的qDrawBorderPixmap函数来实现...

Global site tag (gtag.js) - Google Analytics