56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using System.Diagnostics;
|
|
using System.IO;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using Debug = UnityEngine.Debug;
|
|
|
|
namespace HK
|
|
{
|
|
public static class CitizenPrinterManager
|
|
{
|
|
public static void StartPrinting(string str)
|
|
{
|
|
var text = File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "PrinterCount.txt"));
|
|
int num = 1;
|
|
int.TryParse(text, out num);
|
|
|
|
string parameter = str;
|
|
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
try
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
string path = "";
|
|
#if UNITY_EDITOR
|
|
path = @"C:\ZXL\VS_Project\CitizenPrinter_Win\CitizenPrinter\bin\Release\CitizenPrinter.exe";
|
|
#else
|
|
path = @"CitizenPrinter.exe";
|
|
#endif
|
|
startInfo.FileName = path;
|
|
startInfo.Arguments = parameter;
|
|
startInfo.CreateNoWindow = true; // 不创建新窗口
|
|
startInfo.UseShellExecute = false; // 不使用系统外壳程序启动
|
|
startInfo.WindowStyle = ProcessWindowStyle.Hidden; // 窗口隐藏
|
|
|
|
Process process = new Process();
|
|
process.StartInfo = startInfo;
|
|
process.Start();
|
|
|
|
// 若需要等待进程执行完毕,可取消注释下面这行代码
|
|
process.WaitForExit();
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("启动外部进程时出错: " + e.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static async UniTask StartPrintingAsync(string str)
|
|
{
|
|
await UniTask.Yield();
|
|
StartPrinting(str);
|
|
}
|
|
}
|
|
} |