调用批处理
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bichuli : MonoBehaviour
{
private void Start()
{
buttonOnClick();
}
public void buttonOnClick()
{
ExecuteProgram("批处理文件名字", "路径", "参数");
}
static bool ExecuteProgram(string exeFilename, string workDir, string args)
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.FileName = exeFilename;
info.WorkingDirectory = workDir;
info.UseShellExecute = true;
info.Arguments = args;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process task = null;
bool rt = true;
try
{
Debug.Log("ExecuteProgram:" + args);
task = System.Diagnostics.Process.Start(info);
if (task != null)
{
task.WaitForExit(100000);
}
else
{
return false;
}
}
catch (Exception e)
{
Debug.LogError("ExecuteProgram:" + e.ToString());
return false;
}
finally
{
if (task != null && task.HasExited)
{
rt = (task.ExitCode == 0);
}
}
return rt;
}
}
文本写入
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class krpanno : MonoBehaviour
{
private static int linecount = 0;
private static List<string> vtourconfig = new List<string>();
private void Start()
{
PanoConfig();
PI();
}
public static void PanoConfig()
{
using (StreamReader sr = new StreamReader("文本路径"))
{
//判断文件流是否读取完成
while (sr.Peek() >= 0)
{
//将文本内容的每行存入链表中
vtourconfig.Insert(linecount++, sr.ReadLine());
}
}
}
public void PI()
{
FileStream fs = null;
//删除指示输出tilepath位置的内容,再添加重写添加想要输入的位置
//此处知道其为链表第30个元素,不知道也可以exits/contains找出
//也可以对其他内容进行修改
vtourconfig.RemoveAt(31);
vtourconfig.Insert(31, "tilepath=要设置的位置/panos/%BASENAME%.tiles/pano[_c].jpg");
//创建一个新文件流,将链表中的内容写入到指定文本中
//newconfigpath为配置文件存放的绝对路径加上配置文件名称,名称可以不设为vtour-normal.config,只要.bat调用时使用这个名称就行
fs = new FileStream("C:/Users/sunqu/Desktop/Krpano/krpano-1.19-pr13/templates/vtour-normal.config", FileMode.Create);
using (StreamWriter sw = new StreamWriter(fs))
{
for (int i = 0; i < linecount; i++)
{
sw.WriteLine(vtourconfig[i]);
}
//清理缓冲区,关闭并释放资源
sw.Flush();
sw.Close();
fs.Close();
}
}
}