执行exe程序、打开文件
当我们想在Unity 编辑器下 通过exe程序打开指定脚本时我们可以调用以下API
这里我是通过vscode 打开 lua 脚本 并定位到具体某一行。
static void OpenFile(string path, int line)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "D:/Software/Microsoft VS Code/Code.exe";
startInfo.Arguments = string.Format("-g {0}:{1}", path, line);
process.StartInfo = startInfo;
process.Start();
}
也可以调用Unity内置方法打开脚本,不过调用这个会打开整个Unity工程,并只能用unity指定的编辑器打开
UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path,line);