unity 通用shell运行脚本

Unity 通用环境下跑shell脚本的工具

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

public class ScriptHelper  {

    public void RunScript(string scriptName  , List<string> args = null, string workDir = null)
    {
        string exeName = "";
#if UNITY_EDITOR_WIN
        exeName = "cmd.exe";
#elif UNITY_EDITOR_OSX
        exeName = "sh";
#endif
        string arg = scriptName;
        if (args != null)
        {
            for (int j = 0; j < args.Count; j++)
            {
                arg = arg + " " + args[j];
            }
        }
        Process proc = new Process
        {
            StartInfo =
            {
                FileName = exeName,
                Arguments = arg,
                CreateNoWindow = true,
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = false,
                ErrorDialog =  true,
                WorkingDirectory =  workDir,
            }
        };
        proc.Start();
        proc.WaitForExit();
        proc.Close();
    }
}

没有实际测过,有bug同学可以直接找我留言或者qq610162816

猜你喜欢

转载自blog.csdn.net/thrt520asd/article/details/85765987