Unity调用Windows弹出确认框
退出系统的时候会弹出来,ALT+f4也可以弹出来
直接上代码吧
using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System; using UnityEngine; public class Message_ { [DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] public static extern int MessageBox(IntPtr handle, string message, string title, int type); } public class Message: MonoBehaviour { void OnApplicationQuit() { Application.CancelQuit(); int returnNum = Message_.MessageBox(IntPtr.Zero, "确定退出游戏吗?", "Demo", 1); if (returnNum == 1) { //点击确定按钮 Application.Quit(); } } }
简单记录一下