• 您的位置(zhì):首頁 > 新聞動態 > Unity3D

    Unity3D跨屏幕、全(quán)屏顯示方法

    2019/12/14      點擊:

    Unity3D跨屏幕、全屏顯示方法,運行環境:Win10 64bit, Unity3D 2017.3.1

    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);
            }
        }
    }


    上麵這(zhè)個腳本,可以(yǐ)使Unity3D窗口全(quán)屏,沒有標題欄(lán),通(tōng)過更改screenPosition的值,還可(kě)以使窗口直接在第二個屏幕上啟動(x=0, y=0, width=1920, height=1080),或者(zhě)窗口跨越(yuè)兩(liǎng)個屏(x=0, y=0, width=3840, height=1080)。 如果使用讀取配置文件(jiàn)的方法, 可以自(zì)定義屏幕分辨率。Windows係統會記錄軟件(jiàn)的(de)窗口大小和位置(zhì),並記錄在注冊表的\HKEY_CURRENT_USER\Software\xxx\yyy 位(wèi)置,xxx是Unity3D在build設置中的Company Name,yyy是在Build設置中的(de)Product Name。所以如果有時(shí)候窗口大小(xiǎo)有問題,可以先備份注冊(cè)表,再(zài)刪除xxx項。建議每個項目的(de)Product Name不要用默認值,否則打包出來的軟件都會對應到注冊(cè)表裏相同的項。



    日本中出视频|午夜免费福利在线|亚洲精品亚洲人成在线下载|国产高潮流白浆免费观看不卡|偷拍亚洲欧美|亚洲中文字幕久爱亚洲伊人|久久久久香蕉视频|国产欧美日韩一区|久久国产成人亚洲精品影院老金|久久久久中文字幕