unity 跨屏显示

1.代码

/*
 Type:设置分辨率
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.InteropServices;

public class ScreenManager : MonoBehaviour
{
    public static ScreenManager instance;
    private void Awake()
    {
        instance = this;
    }
    [HideInInspector]
    //导入设置窗口函数  
    [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 SetWindowLong(IntPtr hwnd, int _nIndex, long dwNewLong);
    [DllImport("user32.dll")]
    public static extern long GetWindowLong(IntPtr hwd, int nIndex);
    //导入当前活动窗口  
    [DllImport("user32.dll")]
    static extern IntPtr GetActiveWindow();
    //引用windows接口
    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();

    const uint SWP_SHOWWINDOW = 0x0040;//显示窗口
    const int GWL_STYLE = -16;
    const int WS_BORDER = 1;
    /// <summary>
    /// 标题栏
    /// </summary>
    const int WS_CAPTION = 0x00c00000;

    /// <summary>
    /// 标题栏按钮
    /// </summary>
    const int WS_SYSMENU = 0x00080000;
    void Start()
    {
        //编辑器状态下脚本不执行,发布exe脚本执行
#if !UNITY_EDITOR
        //去掉上面的框
        SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER);
        //显示范围
        //第一个0是开始x第二个0是开始y,1920是不是位置,是长度,比如要显示开始是(500,500),而结束要想显示在最后,不是写1920.而是写1920-500的值
        SetWindowPos(GetActiveWindow(), -1, 0, 0, 1920, 1080, SWP_SHOWWINDOW);
#endif
    }
    public void SetScreen(int x,int y,int width,int height)
    {
        //编辑器状态下脚本不执行,发布exe脚本执行
#if !UNITY_EDITOR
        //去掉上面的框
       // SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER);
        //显示范围
        SetWindowPos(GetActiveWindow(), -1, x, y, width, height, SWP_SHOWWINDOW);//
#endif
    }

}


2.发布设置
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值