unity手动选择文件夹保存文件
2017-10-09 10:58
211 查看
闲话不扯,直接开始正题:
1: 找到unity自带的 System.Windows.Forms.dll 文件,我的是在(C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\System.Windows.Forms.dll )
2:在项目中新建文件夹,名字叫 Plugins , 将 System.Windows.Forms.dll 添加进去。
3:设置unity :File - Build Settings... - Player Setting... - Other Settings - Api Compatibility Level 设置成 .NET 2.0
4:创建脚本 System_Windows_Froms.cs
using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using UnityEngine;
public class System_Windows_Froms : MonoBehaviour {
string CompentPath; //接受选择文件的路径
string UnityPath; //接受转成功后的路径 也就是Unity所需要的路径
//自定义文件保存文件夹;
public void SaveCutScreenPath()
{
FolderBrowserDialog fb = new FolderBrowserDialog(); //创建控件并实例化
fb.Description = "选择文件夹";
fb.RootFolder = Environment.SpecialFolder.MyComputer; //设置默认路径
fb.ShowNewFolderButton = false; //创建文件夹按钮关闭
//如果按下弹窗的OK按钮
if (fb.ShowDialog() == DialogResult.OK)
{
//接受路径
CompentPath= fb.SelectedPath;
}
//将路径中的 \ 替换成 / 由于unity路径的规范必须转
UnityPath= CompentPath.Replace(@"\", "/");
print(UnityPath);
//如果 \ 比较多的话
//if (UnityPath.IndexOf("/") > 2)
//{
//UnityPath = CompentPath+ "/";
//print("大于了");
//}
//else {
//print("小于了");
//}
}
}
1: 找到unity自带的 System.Windows.Forms.dll 文件,我的是在(C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\System.Windows.Forms.dll )
2:在项目中新建文件夹,名字叫 Plugins , 将 System.Windows.Forms.dll 添加进去。
3:设置unity :File - Build Settings... - Player Setting... - Other Settings - Api Compatibility Level 设置成 .NET 2.0
4:创建脚本 System_Windows_Froms.cs
using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using UnityEngine;
public class System_Windows_Froms : MonoBehaviour {
string CompentPath; //接受选择文件的路径
string UnityPath; //接受转成功后的路径 也就是Unity所需要的路径
//自定义文件保存文件夹;
public void SaveCutScreenPath()
{
FolderBrowserDialog fb = new FolderBrowserDialog(); //创建控件并实例化
fb.Description = "选择文件夹";
fb.RootFolder = Environment.SpecialFolder.MyComputer; //设置默认路径
fb.ShowNewFolderButton = false; //创建文件夹按钮关闭
//如果按下弹窗的OK按钮
if (fb.ShowDialog() == DialogResult.OK)
{
//接受路径
CompentPath= fb.SelectedPath;
}
//将路径中的 \ 替换成 / 由于unity路径的规范必须转
UnityPath= CompentPath.Replace(@"\", "/");
print(UnityPath);
//如果 \ 比较多的话
//if (UnityPath.IndexOf("/") > 2)
//{
//UnityPath = CompentPath+ "/";
//print("大于了");
//}
//else {
//print("小于了");
//}
}
}
相关文章推荐
- unity手动选择文件夹保存文件
- [Win32]打开文件/保存文件/选择文件夹对话框
- VB6.0 浏览文件夹对话框 选择文件保存路径
- C# 下载 解压 选择文件夹 保存文件 删除目录下文件及文件夹
- Metro style app 文件、文件夹的选择、文件的保存。
- c# 打开、保存文件对话框 和 文件夹选择对话框
- unity 打开文件夹并选择文件
- 弹出打开/保存文件对话框 选择文件夹对话框
- c#保存文件时候的弹出选择要保存的文件夹带新建文件夹效果的类代码
- c#保存文件时候的弹出选择要保存的文件夹带新建文件夹效果的类代码
- python qt(pyqt)的文件打开、文件保存、文件夹选择对话框
- MFC打开文件选择框和多选框,保存文件夹的选择,保存文件路径的选择
- C#下载文件时候弹出选择文件夹保存目录的代码
- unity 浏览文件夹下某一格式文件进行保存
- 选择文件对话框、保存文件对话框、选择文件夹对话框
- winform 中 将listview数据 以excel格式导出 保存在可选择的文件夹下 但文件打开的时候有问题
- C#下载文件时候弹出选择文件夹保存目录的代码
- 使用CFileDialog 同时选择多个文件或文件夹
- VBA读取可选择文件夹下可选择txt文件内容
- Unity 中保存数据到本地文件