using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
public class NetBox2Control : Editor
{
static string exePath;
[MenuItem("MyTool/OpenNetBox2")]
public static void OpenNetBox()
{
UnityEngine.Debug.LogWarning("使用前请配置文件路径");
exePath = @"C:\Users\li\Desktop\server" + "/NetBox2.exe";
Process.Start(exePath);
}
[MenuItem("MyTool/CloseNetBox2")]
public static void CloseNetBox()
{
KillProcess("NetBox2");
}
static void KillProcess(string processName)
{
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
try
{
if (!process.HasExited)
{
if (process.ProcessName == processName)
{
process.Kill();
UnityEngine.Debug.Log("已杀死进程");
}
}
}
catch (System.InvalidOperationException ex)
{
UnityEngine.Debug.Log(ex);
}
}
}
}
|