unity 通用shell執行指令碼
阿新 • • 發佈:2019-01-04
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