1.找到System.Windows.Forms.dll,并放在project中的Plugins文件夹下。 “D:\Unity3D\Editor\Data\Mono\lib\mono\2.0\System.Windows.Forms.dll”
2.打开Player Settings 把.NET 2.0 Subset 改为.NET 2.0;
<span style="font-size:14px;">using UnityEngine; using System.Collections; using System.Windows.Forms; public class screenshots : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } public void Screen(){ SaveFileDialog saveLog = new SaveFileDialog (); saveLog.InitialDirectory="c:\\"; saveLog.Filter="Image File(*.JPG;*.BMP;*.PNG)|*.JPG;*.BMP;*.PNG|All files(*.*)|*.*"; DialogResult result = saveLog.ShowDialog (); if (result == DialogResult.OK) { string path=saveLog.FileName; UnityEngine.Application.CaptureScreenshot(path); } } }</span><strong style="color: rgb(102, 51, 0);font-size:18px;"> </strong>为按钮绑定一个Screen()的方法
在编辑器运行,当出现此弹窗,确定忽略即可。发布成桌面客户端是不会有这个弹窗的。
下面来看运行效果