国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Unity3D在window環(huán)境下多屏、全屏運(yùn)行的解決方案

2019-11-09 17:47:44
字體:
供稿:網(wǎng)友
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


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宝清县| 越西县| 华宁县| 米脂县| 曲阜市| 儋州市| 偏关县| 花莲县| 潼南县| 汉寿县| 密山市| 株洲县| 黎川县| 临泉县| 鄂托克旗| 远安县| 万盛区| 曲松县| 噶尔县| 长宁区| 青铜峡市| 永嘉县| 承德市| 海城市| 肃宁县| 乌鲁木齐市| 庆安县| 巴彦淖尔市| 会泽县| 赣州市| 威信县| 汉川市| 垦利县| 商河县| 天等县| 茶陵县| 高阳县| 武隆县| 隆安县| 陆丰市| 慈利县|