因为最近有需求,想u3d工具栏直接调用bat
网上一堆的相同的办法,但是不好使..都是互相抄袭.
去查了API才知道,那些人根本就没自己测试只是转了..
修改好的脚本,直接上代码
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class ExcelToJsonTools
{
[MenuItem("Tools/MyTool/读取配置表生成Json")]
private static void Run()
{
// 执行bat脚本
RunMyBat("LubanJson.bat", Application.dataPath + "/Luban/");
}
private static void RunMyBat(string batFile, string workingDir)
{
var path = FormatPath(workingDir + batFile);
if (!System.IO.File.Exists(path))
{
Debug.LogError("bat文件不存在:" + path);
}
else
{
System.Diagnostics.Process proc = null;
try
{
proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = workingDir;
proc.StartInfo.FileName = batFile;
//proc.StartInfo.Arguments = args;
//proc.StartInfo.CreateNoWindow = true;
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//disable dos window
proc.Start();
proc.WaitForExit();
proc.Close();
}
catch (System.Exception ex)
{
Debug.LogFormat("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
}
}
}
static string FormatPath(string path)
{
path = path.Replace("/", "\\");
if (Application.platform == RuntimePlatform.OSXEditor)
path = path.Replace("\\", "/");
return path;
}
}