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窗口全屏,沒有標(biāo)題欄,通過更改screenPosition的值,還可以使窗口直接在第二個屏幕上啟動(x=0, y=0, width=1920, height=1080),或者窗口跨越兩個屏(x=0, y=0, width=3840, height=1080)。 Windows系統(tǒng)會記錄每個軟件的窗口大小和位置,記錄在注冊表的/HKEY_CURRENT_USER/Software/xxx/yyy 位置,xxx是Unity3D在build設(shè)置中的Company Name,yyy是在Build設(shè)置中的Product Name。所以如果有時(shí)候窗口大小有問題,可以先備份注冊表,再刪除xxx項(xiàng)。建議每個項(xiàng)目的Product Name不要用默認(rèn)值,否則打包出來的軟件都會對應(yīng)到注冊表里相同的項(xiàng)。
在實(shí)際測試代碼的時(shí)候直接點(diǎn)三角號運(yùn)行了,結(jié)果unity的標(biāo)題欄被隱藏,始終在最前,而且窗口大小改變了……而且改不回來,十分無語……
看來一定要打包后再實(shí)際進(jìn)行測試。
現(xiàn)在只要將腳本綁定到場景物體上,并設(shè)置一下窗口大小就可以使用了
原文鏈接:http://www.chinaar.com/unity/1722.html
另一種方式:
在生成的執(zhí)行文件目錄下創(chuàng)建一個bat文件,寫入內(nèi)容:
demo.exe -popupwindow -screen-width 3840 -screen-height 1080用這個bat啟動程序即可。其中demo.exe替換成你的exe名稱,-screen-width是兩個屏幕分辨率寬度的總和,-screen-height是一個屏幕的高度(當(dāng)然,一般這種情況下,兩個屏幕分辨率都是一致的)
原文鏈接:http://www.chinaar.com/unity/1752.html
新聞熱點(diǎn)
疑難解答