<h4 id="%E8%84%9A%E6%9C%AC1">脚本1</h4> <p>using UnityEngine;<br> using System;<br> using System.Collections;<br> using System.Runtime.InteropServices;</p> <p>public class WindowsSET:MonoSingleton<WindowsSET><br> {</p> <p>#region 窗口最小化定义<br> [DllImport("user32.dll")]<br> static extern bool CloseWindow(IntPtr hwnd);<br> [DllImport("user32.dll", EntryPoint = "FindWindow")]<br> static extern IntPtr FindWindow(string lpClassName, string lpWindowName);<br> IntPtr ParenthWnd = FindWindow(null, "Voices"); //build时候的项目名<br> #endregion</p> <p>private bool ischange = false;</p> <p>/// <br> /// 子物体:关闭程序按钮<br> /// <br> public void CloseBtn_Click()<br> {<br> Application.Quit();<br> }</p> <p>/// <br> /// 子物体:窗口最小化<br> /// <br> public void MinimizeBtn_Click()<br> {<br> CloseWindow(ParenthWnd);<br> }</p> <p>/// <br> /// 子物体:窗口最大化<br> /// <br> public void MaximzeBtn_Click()<br> {<br> <br> if (ischange == true)<br> {<br> Screen.SetResolution(1920,1080,true); //根据自己的需求设置即可<br> }<br> else<br> {<br> //获取设置当前屏幕分辩率 <br> /// Resolution[] resolutions = Screen.resolutions;<br> //设置当前分辨率 <br> //Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);</p> <p>// Screen.fullScreen = true; //设置成全屏,</p> <p>Screen.SetResolution(960,540, false); <br> }<br> ischange = !ischange;<br> }<br> }</p> <h4 id="%E8%84%9A%E6%9C%AC2">脚本2</h4> <p>using System; <br> using System.Collections; <br> using System.Collections.Generic; <br> using System.Runtime.InteropServices; <br> using UnityEngine; <br> public class WindowMaxAndMin : MonoBehaviour <br> {<br> [DllImport("user32.dll")] <br> public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow); <br> [DllImport("user32.dll")] <br> static extern IntPtr GetForegroundWindow(); <br> const int SW_SHOWMINIMIZED = 2; //{最小化, 激活} <br> const int SW_SHOWMAXIMIZED = 3;//最大化 <br> const int SW_SHOWRESTORE = 1;//还原</p> <p>public static void OnClickMinimize()<br> { //最小化 <br> ShowWindow (GetForegroundWindow (), SW_SHOWMINIMIZED); <br> } <br> public static void OnClickMaximize()<br> { <br> //最大化 <br> ShowWindow (GetForegroundWindow (), SW_SHOWMAXIMIZED); <br> }</p> <p>public void OnClickRestore()<br> { <br> //还原 <br> ShowWindow (GetForegroundWindow (), SW_SHOWRESTORE); <br> }</p>