浅谈Unity之实现双屏显示或多个屏幕显示-01

本文涉及的产品
交互式建模 PAI-DSW,5000CU*H 3个月
简介: 实现双屏显示或多个屏幕显示

项目要无边框设置,窗口拖动如下:

using UnityEngine;

using System.Collections;

using System;

using System.Runtime.InteropServices;

using UnityEngine.UI;

public class Drag_i : MonoBehaviour

{

   [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 GetForegroundWindow();

   [DllImport("user32.dll")]

   public static extern bool ReleaseCapture();

   [DllImport("user32.dll")]

   public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

   [DllImport("user32.dll")]

   public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

   //边框参数

   const uint SWP_SHOWWINDOW = 0x0040;

   const int GWL_STYLE = -16;

   const int GWL_STYLE_ = 16;

   const int WS_BORDER = 1;

   const int WS_POPUP = 0x800000;

   const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}

   const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活}  

   public void btn_onclick()

   { //最小化  

       ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);

   }

   public void btn_onclickxx()

   { //最大化

       ShowWindow(GetForegroundWindow(), SW_SHOWMAXIMIZED);

   }

   IntPtr Handle;

   float xx;

   bool bx;

   private void Awake()

   {

#if UNITY_STANDALONE_WIN

       //框体大小设置

       float windowWidth = 1024;

       float windowHeight = 768;

       //计算框体显示位置

       float posX = (Screen.currentResolution.width - windowWidth) / 2;

       float posY = (Screen.currentResolution.height - windowHeight) / 2;

       Rect rect = new Rect(posX, posY, windowWidth, windowHeight);

       //去边框

       //SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_BORDER);//将网上的WS_BORDER替换成WS_POPUP  测试之后,不换好像有点卡顿,又好像无影响

       //显示边框

       SetWindowLong(GetForegroundWindow(), GWL_STYLE_, WS_POPUP);

       Handle = GetForegroundWindow();   //FindWindow ((string)null, "popu_windows");

       SetWindowPos(GetForegroundWindow(), 0, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height, SWP_SHOWWINDOW);

#endif

   }

   void Start()

   {

       bx = false;

       xx = 0f;

   }

   //update 是设置窗口可以拖动

   void Update()

   {

   

#if UNITY_STANDALONE_WIN

       if (Input.GetMouseButtonDown(0))

       {

           xx = 0f;

           bx = true;

       }

       if (bx && xx >= 0.3f)

       { //这样做为了区分界面上面其它需要滑动的操作

           ReleaseCapture();

           SendMessage(Handle, 0xA1, 0x02, 0);

           SendMessage(Handle, 0x0202, 0, 0);

       }

       if (bx)

           xx += Time.deltaTime;

       if (Input.GetMouseButtonUp(0))

       {

           xx = 0f;

           bx = false;

       }

#endif

   }

}


相关文章
|
8月前
|
数据采集 开发工具 图形学
Windows平台实现Unity下窗体|摄像头|屏幕采集推送
随着Unity3D的应用范围越来越广,越来越多的行业开始基于Unity3D开发产品,如传统行业中虚拟仿真教育、航空工业、室内设计、城市规划、工业仿真等领域。
|
8月前
|
图形学
|
vr&ar 图形学
【Unity3D 灵巧小知识点】☀️ | Unity 屏幕坐标 和 世界坐标 之间相互转换
Unity 小科普 老规矩,先介绍一下 Unity 的科普小知识: Unity是 实时3D互动内容创作和运营平台 。 包括游戏开发、美术、建筑、汽车设计、影视在内的所有创作者,借助 Unity 将创意变成现实。
|
图形学 编解码 Android开发
|
图形学 开发者
Unity Debug输出到屏幕并保存到本地
借鉴了往网上两位开发者的文章,自己整理了下http://www.gad.qq.com/lore/detail/10119http://blog.csdn.
1250 0
|
5月前
|
C# 图形学
【Unity 3D】元宇宙案例之虚拟地球信息射线实战(附源码、演示视频和步骤 超详细)
【Unity 3D】元宇宙案例之虚拟地球信息射线实战(附源码、演示视频和步骤 超详细)
50 0