ict.lixian.three/Assets/Scripts/WindowToolMgr.cs

154 lines
3.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using static ResolutionTest;
/*xbb
*
* */
public class WindowsToolMgr : MonoBehaviour
{
public static WindowsToolMgr instance;
private void Awake()
{
instance = this;
}
//系统方法类实体
public WindowsTools winTool = new WindowsTools();
//当前Unity程序进程
private static IntPtr currentWindow;
void Start()
{
currentWindow = WindowsTools.GetForegroundWindow();
}
//最小化窗口
public void MinWindows()
{
winTool.SetMinWindows(currentWindow);
}
//设置无边框窗口
[Obsolete("使用SetNoFrame(int _width, int _height,int _posx,int _posy)")]
public void SetNoFrame(int _width, int _height)
{
//窗口大小 以此为例
float windowWidth = _width;
float windowHeight = _height;
//计算框体显示位置
float posX = (Screen.currentResolution.width - windowWidth) / 2;
float posY = (Screen.currentResolution.height - windowHeight) / 2;
Rect _rect = new Rect(posX, posY, windowWidth, windowHeight);
winTool.SetNoFrameWindow(currentWindow, _rect);
}
public void SetNoFrame(int _width, int _height,int _posx,int _posy)
{
//窗口大小 以此为例
float windowWidth = _width;
float windowHeight = _height;
Rect _rect = new Rect(_posx, _posy, windowWidth, windowHeight);
winTool.SetNoFrameWindow(currentWindow, _rect);
}
public void SetFrame(int _width, int _height, int _posx, int _posy)
{
//窗口大小 以此为例
float windowWidth = _width;
float windowHeight = _height;
Rect _rect = new Rect(_posx, _posy, windowWidth, windowHeight);
winTool.SetFrameWindow(currentWindow, _rect);
}
[HideInInspector]
public int width;
[HideInInspector]
public int height;
/// <summary>
/// 切换分辨率
/// </summary>
/// <returns> 是否为小窗口</returns>
public void SwitchScreenResolution(int _width, int _height, bool _full_screen = false)
{
//if (Screen.width == 1600 && Screen.height == 900)
//{
// res = true;
// Screen.SetResolution(280, 160, false);
//}
//else
//{
// res = false;
// Screen.SetResolution(1600, 900, false);
//}
Screen.SetResolution(_width, _height, _full_screen);
width = Screen.width;
height = Screen.height;
//等待当前帧完成 再去除边框
//StartCoroutine(IE_NoFrame(width, height));
}
public void SwitchScreenResolution(int[] _size, bool _full_screen = false)
{
//if (Screen.width == 1600 && Screen.height == 900)
//{
// res = true;
// Screen.SetResolution(280, 160, false);
//}
//else
//{
// res = false;
// Screen.SetResolution(1600, 900, false);
//}
Screen.SetResolution(_size[0], _size[1], _full_screen);
width = Screen.width;
height = Screen.height;
//等待当前帧完成 再去除边框
//StartCoroutine(IE_NoFrame(width, height));
}
public RECT GetRect()
{
return winTool.GetWinRect(currentWindow);
}
private IEnumerator IE_NoFrame(int _width, int _height)
{
yield return new WaitForEndOfFrame();
yield return new WaitForFixedUpdate();
if (!Screen.fullScreen)
{
SetNoFrame(_width, _height);
}
}
//窗口拖动
public void Drag()
{
winTool.DragWindow(currentWindow);
}
public void Drop()
{
winTool.DragWindowEnd(currentWindow);
}
public void SetTopping(bool _is_topping)
{
if (_is_topping)
winTool.SetTopMost(currentWindow);
else
winTool.CancelTopMost(currentWindow);
}
}