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

首頁 > 學院 > 開發設計 > 正文

Unity3D在window環境下多屏、全屏運行的解決方案

2019-11-09 16:46:30
字體:
來源:轉載
供稿:網友
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窗口全屏,沒有標題欄,通過更改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不要用默認值,否則打包出來的軟件都會對應到注冊表里相同的項。

在實際測試代碼的時候直接點三角號運行了,結果unity的標題欄被隱藏,始終在最前,而且窗口大小改變了……而且改不回來,十分無語……

看來一定要打包后再實際進行測試。

現在只要將腳本綁定到場景物體上,并設置一下窗口大小就可以使用了

原文鏈接:http://www.chinaar.com/unity/1722.html

另一種方式:

在生成的執行文件目錄下創建一個bat文件,寫入內容: 

demo.exe -popupwindow -screen-width 3840 -screen-height 1080 

用這個bat啟動程序即可。其中demo.exe替換成你的exe名稱,-screen-width是兩個屏幕分辨率寬度的總和,-screen-height是一個屏幕的高度(當然,一般這種情況下,兩個屏幕分辨率都是一致的) 

原文鏈接:http://www.chinaar.com/unity/1752.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天气| 甘泉县| 洞头县| 芦山县| 开江县| 陵水| 姜堰市| 安阳市| 莲花县| 辽宁省| 曲阜市| 象州县| 连城县| 察哈| 安阳县| 琼结县| 双鸭山市| 香港| 陇南市| 乐清市| 乐山市| 武强县| 吉水县| 湖南省| 华阴市| 洪洞县| 宝应县| 韶山市| 东乡县| 永顺县| 九寨沟县| 望谟县| 黄龙县| 通海县| 贺兰县| 来安县| 思南县| 北票市| 昭平县| 贡嘎县| 徐水县|