C# 文件选择对话框,Unity3d文件保存对话框
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C# 文件选择对话框,Unity3d文件保存对话框,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2192字,纯文字阅读大概需要4分钟。
内容图文
using OpenWinForm = System.Windows.Forms;
在unity3d中,使用FileDialog应该把System.Windows.Forms.dll拷贝到unity工程的plugins目录,
并且把Player Setting中Other Settings下的api compatibility Level改为.NET2.0。要不无法编译通过。
//比如unity3d要让用户选择某一个音乐文件播放;
private void SelectMusic(){
OpenWinForm.OpenFileDialog op = new OpenWinForm.OpenFileDialog();
op.Title = "音乐";
op.Filter = "音频文件(*.wav;*.ogg)|*.wav;*.ogg";
if (op.ShowDialog() == OpenWinForm.DialogResult.OK || op.ShowDialog() == OpenWinForm.DialogResult.Yes)
{
string selectName = op.FileName;
customBgmPath.text = selectName;
string path = customBgmPath.text;
WWW www = new WWW("file://"+path);
if(www.audioClip){
AudioClip clip = www.audioClip;
AudioPlayCtr.instance.ChangeBgMusic(clip);
}
}
else {
return;
}
}
//自定义文件保存文件夹;
private void SaveCutScreenPath()
{
OpenWinForm.FolderBrowserDialog fb = new OpenWinForm.FolderBrowserDialog();
fb.ShowNewFolderButton = true;
fb.RootFolder = Environment.SpecialFolder.MyDocuments;
fb.SelectedPath = "C:";
fb.Description = "请选择截图保存目录";
fb.RootFolder = Environment.SpecialFolder.MyDocuments;
if (fb.ShowDialog() == OpenWinForm.DialogResult.OK || fb.ShowDialog() == OpenWinForm.DialogResult.Yes)
{
string selectName = fb.SelectedPath;
customCutScreenPath.text = selectName;
}
else {
return;
}
}
//比如unity3d截图后,弹出对话框用户选择保存路径;
public IEnumerator CutScreent() {
int width = Screen.width;
int height = Screen.height;
yield return new WaitForEndOfFrame();
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);//设置Texture2D
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);//获取Pixels
tex.Apply();//应用改变
byte[] bytes = tex.EncodeToPNG();//转换为byte[]
Destroy(tex);
OpenWinForm.SaveFileDialog saveFileDialog = new OpenWinForm.SaveFileDialog();
saveFileDialog.Filter = "图像文件(*.png)|*.png";
saveFileDialog.FilterIndex = 2;
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == OpenWinForm.DialogResult.OK)
{
string fName = saveFileDialog.FileName;
Stream flstr = new FileStream(fName, FileMode.Create);//文件操作
BinaryWriter sw = new BinaryWriter(flstr, System.Text.Encoding.Unicode);
sw.Write(bytes);
sw.Close();
flstr.Close();
}
}
原文:http://www.cnblogs.com/2Yous/p/5079991.html
内容总结
以上是互联网集市为您收集整理的C# 文件选择对话框,Unity3d文件保存对话框全部内容,希望文章能够帮你解决C# 文件选择对话框,Unity3d文件保存对话框所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。