方案1 unity中2個攝像機場景顯示在兩個顯示器屏幕上(一個窗口跨屏)
1.設置場景中的兩個攝像機
攝像機1
攝像機2
2.設置發布的平台及分辨率
3.全屏運行游戲,沒有標題欄還可以通過-popupwindow
例如:
G:\untiy3d_workspace\Demos>lol_demo_0515 -popupwindow
方案2
http://blog.csdn.net/a117653909/article/details/47101743
環境:Win7 64bit, Unity3D 4.6.2
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() { SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER); SetWindowPos(GetActiveWindow(), -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW); } void Update() { i++; if(i<5) { SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER); SetWindowPos(GetActiveWindow(), -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW); } } }
上圖,Build設置
用這個腳本,可以使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不要用默認值,否則打包出來的軟件都會對應到注冊表里相同的項。