Unity3D截图并保存本地目录

来源:互联网 发布:ios图片内存优化 编辑:程序博客网 时间:2024/05/11 02:49

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 initializationvoid Start () {}// Update is called once per framevoid 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()的方法

在编辑器运行,当出现此弹窗,确定忽略即可。发布成桌面客户端是不会有这个弹窗的。


下面来看运行效果


0 0
原创粉丝点击