在Unity编辑器中打开本地文件夹

1、仅限编辑器可用 

using UnityEngine;
using UnityEditor;
 
public class FolderSelector : MonoBehaviour
{
    void Start()
    {
        // 调用OpenFolderPanel,其中参数分别是标题、默认路径、是否显示文件扩展名
        string folderPath = EditorUtility.OpenFolderPanel("Select Folder", "", "");
        if (folderPath.Length != 0)
        {
            Debug.Log("Selected Folder: " + folderPath);
        }
    }
}

2、发布可用(Windows)

using SFB;    

    string folderPath;
    private string _path;
    void OpenFileEvent()
    {
        /*EditorUtility.OpenFolderPanel("Select Folder", "", "");*/
        folderPath = WriteResult(StandaloneFileBrowser.OpenFolderPanel("Select Folder", "", true));

        if (folderPath.Length != 0)
        {
            fileName_txt.text = folderPath;
        }
    }

    public string WriteResult(string[] paths)
    {
        if (paths.Length == 0)
        {
            return null;
        }

        _path = "";
        for (int i = 0; i < paths.Length; i++)
        {
            _path += i < paths.Length - 1 ? (paths[i] + "\n") : paths[i];

        }
        return _path;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值