Unity3D在window环境下多屏、全屏运行的解决方案
来源:互联网 发布:java 获取当前日期 编辑:程序博客网 时间:2024/05/22 13:23
using System;using System.Collections;using System.Runtime.InteropServices;using System.Diagnostics;using UnityEngine;using System.Xml.Serialization;public class WindowMod : MonoBehaviour { // [HideInInspector] public Rect screenPosition; [DllImport("user32.dll")] static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong); [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 GetActiveWindow(); const uint SWP_SHOWWINDOW = 0x0040; const int GWL_STYLE = -16; const int WS_BORDER = 1; private int i = 0; void Start() {#if UNITY_STANDALONE_WIN SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER); SetWindowPos(GetActiveWindow(), -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW); #endif } void Update() { i++; if(i<5) { #if UNITY_STANDALONE_WIN SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER); SetWindowPos(GetActiveWindow(), -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW); #endif } } }
用这个脚本,可以使Unity3D窗口全屏,没有标题栏,通过更改screenPosition的值,还可以使窗口直接在第二个屏幕上启动(x=0, y=0, width=1920, height=1080),或者窗口跨越两个屏(x=0, y=0, width=3840, height=1080)。 Windows系统会记录每个软件的窗口大小和位置,记录在注册表的\HKEY_CURRENT_USER\Software\xxx\yyy 位置,xxx是Unity3D在build设置中的Company Name,yyy是在Build设置中的Product Name。所以如果有时候窗口大小有问题,可以先备份注册表,再删除xxx项。建议每个项目的Product Name不要用默认值,否则打包出来的软件都会对应到注册表里相同的项。
在实际测试代码的时候直接点三角号运行了,结果unity的标题栏被隐藏,始终在最前,而且窗口大小改变了……而且改不回来,十分无语……
看来一定要打包后再实际进行测试。
现在只要将脚本绑定到场景物体上,并设置一下窗口大小就可以使用了
原文链接:http://www.chinaar.com/unity/1722.html
另一种方式:
在生成的执行文件目录下创建一个bat文件,写入内容:
demo.exe -popupwindow -screen-width 3840 -screen-height 1080
用这个bat启动程序即可。其中demo.exe替换成你的exe名称,-screen-width是两个屏幕分辨率宽度的总和,-screen-height是一个屏幕的高度(当然,一般这种情况下,两个屏幕分辨率都是一致的)
原文链接:http://www.chinaar.com/unity/1752.html
- Unity3D在window环境下多屏、全屏运行的解决方案
- QML 在Window下全屏的使用
- 如何在Window XP下安装Android运行环境
- 如何在Window XP下安装Android运行环境
- 机会网络平台haggle在Ubuntu下的运行环境配置过程遇到问题的解决方案
- nutch2.x在eclipse+windows环境下运行遇到的一些问题的解决方案
- 关于Selenium脚本在Win7 IE8环境下不能运行的问题及解决方案
- JasperReport在linux环境下运行时找不到字体的解决方案
- 有关于在Extjs4环境中,window窗口下的messageBox弹窗的bug以及解决方案
- bochs在window环境下的调试
- bochs在window环境下的调试
- bochs在window环境下的调试
- php在window上下的环境搭建
- python在window上的环境搭建
- Unity3d在浏览器中全屏显示
- 在desktop应用中的window中打开另一个网页的代码解决flexpaper在window中不能全屏
- android 模拟window运行环境
- Service在后台长期运行的解决方案
- dubbo源码:服务发布详解
- 设计模式初探(二)「Facade模式」
- JS特效之星星打分效果
- [POJ2407]欧拉函数的值
- SVN两种使用方式
- Unity3D在window环境下多屏、全屏运行的解决方案
- android EditText自动获取焦点
- 自动控制理论的发展历程
- Angular封装指令回到顶部以及滚动到特定的页面位置
- centos7上安装DUCKER并配置
- 应届生入职练手习题-蒙特卡洛算法(1.5H)
- 统计MySQL中每条sql的执行时间
- chrome开发工具特性
- poj3414 倒水并输出过程