zoukankan      html  css  js  c++  java
  • unity 打开指定路径文件夹

    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

  • 相关阅读:
    【Flask-RESTPlus系列】Part3:请求解析
    【Flask-RESTPlus系列】Part2:响应编组
    【Flask-RESTPlus系列】Part1:快速入门
    webpack中hash、chunkhash、contenthash区别
    如何将现有 git 仓库中的子项目单独抽出来作为一个独立仓库并保留其提交历史
    Using Immutable in React + React-Redux
    ChromeExtension那些事儿
    Get started with Google Analytics
    middlewares in GCC
    实现一个简单的虚拟DOM
  • 原文地址:https://www.cnblogs.com/kingBook/p/11602507.html
Copyright © 2011-2022 走看看