码迷,mamicode.com
首页 > 编程语言 > 详细

unity 打开指定路径文件夹

时间:2019-09-28 12:55:13      阅读:671      评论:0      收藏:0      [点我收藏+]

标签:name   文件夹   proc   close   oid   roc   director   stand   erro   

public static void OpenDirectory(string path){
    if (string.IsNullOrEmpty(path)) return;

    path=path.Replace("/", "\\");
    if (!Directory.Exists(path)){
        Debug.LogError("No Directory: " + path);
        return;
    }
    //可能360不信任
    System.Diagnostics.Process.Start("explorer.exe", path);
}
public static void OpenDirectory(string path){
    // 新开线程防止锁死
    Thread newThread=new Thread(new ParameterizedThreadStart(CmdOpenDirectory));
    newThread.Start(path);
}

private static void CmdOpenDirectory(object obj){
    Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.Arguments = "/c start " + obj.ToString();
    UnityEngine.Debug.Log(p.StartInfo.Arguments);
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = true;
    p.Start();

    p.WaitForExit();
    p.Close();
}

支持MAC

public static void OpenDirectory(string path){
    if (string.IsNullOrEmpty(path)) return;

    if (!Directory.Exists(path)){
        UnityEngine.Debug.LogError("No Directory: " + path);
        return;
    }

    //Application.dataPath 只能在主线程中获取
    int lastIndex = Application.dataPath.LastIndexOf("/");
    shellPath = Application.dataPath.Substring(0, lastIndex) + "/Shell/";

    // 新开线程防止锁死
    Thread newThread = new Thread(new ParameterizedThreadStart(CmdOpenDirectory));
    newThread.Start(path);
}

private static void CmdOpenDirectory(object obj){
    Process p = new Process();
#if UNITY_EDITOR_WIN
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.Arguments = "/c start " + obj.ToString();
#elif UNITY_EDITOR_OSX
    p.StartInfo.FileName = "bash";
    string shPath = shellPath + "openDir.sh";
    p.StartInfo.Arguments = shPath + " " + obj.ToString();
#endif
    //UnityEngine.Debug.Log(p.StartInfo.Arguments);
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = true;
    p.Start();

    p.WaitForExit();
    p.Close();
}

openDir.sh

#!/bin/bash
tempDirectory=$*
 
echo "${tempDirectory}"
open "${tempDirectory}"

https://blog.csdn.net/zp288105109a/article/details/81366343

unity 打开指定路径文件夹

标签:name   文件夹   proc   close   oid   roc   director   stand   erro   

原文地址:https://www.cnblogs.com/kingBook/p/11602507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!