利来w66国际平台

  • 联系利来w66国际平台    Contact

    Unity3D跨屏幕、全屏显示方法

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


    SHANGMIANZHEIGEJIAOBEN,KEYISHIUnity3DCHUANGKOUQUANPING,MEIYOUBIAOTILAN,TONGGUOGENGGAIscreenPositionDEZHI,HAIKEYISHICHUANGKOUZHIJIEZAIDIERGEPINGMUSHANGQIDONG(x=0, y=0, width=1920, height=1080),HUOZHECHUANGKOUKUAYUELIANGGEPING(x=0, y=0, width=3840, height=1080)。 RUGUOSHIYONGDUQUPEIZHIWENJIANDEFANGFA, KEYIZIDINGYIPINGMUFENBIANLV。WindowsXITONGHUIJILURUANJIANDECHUANGKOUDAXIAOHEWEIZHI,BINGJILUZAIZHUCEBIAODE\HKEY_CURRENT_USER\Software\xxx\yyy WEIZHI,xxxSHIUnity3DZAIbuildSHEZHIZHONGDECompany Name,yyySHIZAIBuildSHEZHIZHONGDEProduct Name。SUOYIRUGUOYOUSHIHOUCHUANGKOUDAXIAOYOUWENTI,KEYIXIANBEIFENZHUCEBIAO,ZAISHANCHUxxxXIANG。JIANYIMEIGEXIANGMUDEProduct NameBUYAOYONGMORENZHI,FOUZEDABAOCHULAIDERUANJIANDOUHUIDUIYINGDAOZHUCEBIAOLIXIANGTONGDEXIANG。