unity笔记之运行bat命令工具
前言:运行bat有好几种方法都可以执行,我选择的是process
static void Run()
{
// 指定批处理文件的路径
string pathToBatchFile = $"{Application.dataPath}".Replace("Assets", "Luban") + "/gen.bat";
Process process = new Process();
// 设置进程启动信息
process.StartInfo.FileName = pathToBatchFile;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
// 启动进程
process.Start();
// 读取输出(如果需要)
string output = process.StandardOutput.ReadToEnd();
string errors = process.StandardError.ReadToEnd();
// 等待进程结束
process.WaitForExit();
// 可以将输出或错误信息打印到Unity的控制台
UnityEngine.Debug.Log(output);
if (!string.IsNullOrEmpty(errors))
{
UnityEngine.Debug.LogError(errors);
}
Debug.Log("配置文件生成成功,开始生成常量脚本");
// 自动生成脚本
GenConst();
}
需要自己删除点代码哈。

浙公网安备 33010602011771号