Unity3D 发布无边框exe
2018-02-02 23:09
489 查看
转载自: https://www.cnblogs.com/2Yous/p/5079985.html
关于:Unity3D 发布无边框exe,Unity3D Build exe无边框
Unity发布windows版本 总是带着边框,很想给它去掉,笔者在网上查了一番,常见的有3中。
1:通过unity3d编译命令解决:
-popupwindow (Windows only)The window will be created as a a pop-up window (without a frame).
这个窗口将以弹出的方式创建(没有框架)
笔者就是这样的CMD:
【D:\Program Files (x86)\Unity\Editor>Unity.exe -buildWindowsPlayer "D:\Game.exe" -projectPath "D:\Work\Game3D" -popupwindow -executeMethod CMDBuild.MyBuild -quit】
其中CMDBuild.MyBuild 代码如下:
[MenuItem("Build/BuildWebplayerStreamed")]
static void MyBuild(){
string[] levels= new string[]{"Assets/Scenes/Load.unity", "Assets/Scenes/Main2.unity"};
BuildPipeline.BuildPlayer(levels,"Game.exe",BuildTarget.StandaloneWindows,BuildOptions.BuildAdditionalStreamedScenes);
}
更多编译命令中文内容参见圣典:
http://game.ceeger.com/Manual/CommandLineArguments.html
//官方的新命令有所更新,参见:
http://docs.unity3d.com/Manual/CommandLineArguments.html
2:C# 中通过 P/Invoke 调用Win32 DLL。通过user32.dll 完成exe边框的设置。如下建一个WindowMod.cs;
public class WindowMod : MonoBehaviour
{
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 GetForegroundWindow();
// not used rigth now
//const uint SWP_NOMOVE = 0x2;
//const uint SWP_NOSIZE = 1;
//const uint SWP_NOZORDER = 0x4;
//const uint SWP_HIDEWINDOW = 0x0080;
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
void Awake()
{
screenPosition.x = (int)((Screen.currentResolution.width - screenPosition.width) / 2);
screenPosition.y = (int)((Screen.currentResolution.height - screenPosition.height) / 2);
if(Screen.currentResolution.height<=768){
screenPosition.y = 0;
}
SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_BORDER);//设置无框;
bool result = SetWindowPos(GetForegroundWindow(), 0, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);//exe居中显示;
}
}
标签: Unity3D原生
关于:Unity3D 发布无边框exe,Unity3D Build exe无边框
Unity发布windows版本 总是带着边框,很想给它去掉,笔者在网上查了一番,常见的有3中。
1:通过unity3d编译命令解决:
-popupwindow (Windows only)The window will be created as a a pop-up window (without a frame).
这个窗口将以弹出的方式创建(没有框架)
笔者就是这样的CMD:
【D:\Program Files (x86)\Unity\Editor>Unity.exe -buildWindowsPlayer "D:\Game.exe" -projectPath "D:\Work\Game3D" -popupwindow -executeMethod CMDBuild.MyBuild -quit】
其中CMDBuild.MyBuild 代码如下:
[MenuItem("Build/BuildWebplayerStreamed")]
static void MyBuild(){
string[] levels= new string[]{"Assets/Scenes/Load.unity", "Assets/Scenes/Main2.unity"};
BuildPipeline.BuildPlayer(levels,"Game.exe",BuildTarget.StandaloneWindows,BuildOptions.BuildAdditionalStreamedScenes);
}
更多编译命令中文内容参见圣典:
http://game.ceeger.com/Manual/CommandLineArguments.html
//官方的新命令有所更新,参见:
http://docs.unity3d.com/Manual/CommandLineArguments.html
2:C# 中通过 P/Invoke 调用Win32 DLL。通过user32.dll 完成exe边框的设置。如下建一个WindowMod.cs;
public class WindowMod : MonoBehaviour
{
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 GetForegroundWindow();
// not used rigth now
//const uint SWP_NOMOVE = 0x2;
//const uint SWP_NOSIZE = 1;
//const uint SWP_NOZORDER = 0x4;
//const uint SWP_HIDEWINDOW = 0x0080;
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
void Awake()
{
screenPosition.x = (int)((Screen.currentResolution.width - screenPosition.width) / 2);
screenPosition.y = (int)((Screen.currentResolution.height - screenPosition.height) / 2);
if(Screen.currentResolution.height<=768){
screenPosition.y = 0;
}
SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_BORDER);//设置无框;
bool result = SetWindowPos(GetForegroundWindow(), 0, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);//exe居中显示;
}
}
标签: Unity3D原生
相关文章推荐
- Unity3D 发布无边框exe
- Unity3d发布成exe项目后的设置(全屏自适应屏幕大小)
- Unity3d 去掉exe版本的边框
- unity3d发布PC端后的exe程序,怎么保证只能开一个实例,不能多开?
- Unity3D 发布成exe之后黑屏
- Unity3d 去掉exe版本的边框
- Unity3d发布成exe项目后的设置(全屏自适应屏幕大小)
- Unity3D打包 将发布的exe文件打包成一个Windows安装文件(自解压文件)
- Unity3d 去掉exe版本的边框
- Unity3d:编辑器中运行正常,发布后的exe提示找不到文件
- Unity3d 发布EXE安装程序
- Unity3D 去掉 exe 边框
- Unity3D发布为exe后无法连接数据库问题
- 此博文包含图片Unity3d发布成exe项目后的设置
- 【Unity3D自学记录】Unity3D去掉exe版本的边框
- Unity3d 去掉exe版本的边框
- Unity3d 发布EXE安装程序
- 反编译unity3d发布apk
- Unity3d 发布lash
- Unity3D的WebGL开发(一)发布设置