關於: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居中顯示;
}
}