Unity3D 发布无边框exe

关于: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)UnityEditor>Unity.exe -buildWindowsPlayer "D:Game.exe" -projectPath "D:WorkGame3D" -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居中显示;
    }
}

原文地址:https://www.cnblogs.com/2Yous/p/5079985.html