我们的程序可能需要一个最小化程序的按钮,但是Unity没有直接为我们提供该方法.
所以我们需要使用调用Windows的api来最小化我们的程序,废话少说直接上代码.
#region 最小化
[DllImport("user32.dll")]
public static extern bool ShowWindow(System.IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
static extern System.IntPtr GetForegroundWindow();
const int SW_SHOWMINIMIZED = 2;
void OnClick_Min()
{
ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
}
#endregion
将你的按钮绑定OnClick_Min()方法就可以了.
注意:编辑器环境可能无效,如果无效打包试下