unity手动选择文件夹保存文件

闲话不扯,直接开始正题:

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("小于了");
        //}


    }

}

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值