在原项目新建一个批处理文件 duokaipc.bat 和Assets文件夹同级
@echo off
for %%d in (%~dp0..) do set ParentDirectory=%%~fd
pushd %1 & for %%i in (.) do set curr=%%~ni
set filename=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
set "filename=%filename: =0%"
set src=%cd%
echo 原始工程目录 %src%
set dir=%ParentDirectory%\%curr%_%filename%
echo 要创建的目录 %dir%
set assets="\Assets"
set configexcels="\ConfigExcels"
set packages="\Packages"
set library="\Library"
set projectsettings="\ProjectSettings"
if not exist %dir% ( md %dir%)
mklink/J %dir%%assets% %src%%assets%
mklink/J %dir%%configexcels% %src%%configexcels%
mklink/J %dir%%packages% %src%%packages%
mklink/J %dir%%library% %src%%library%
mklink/J %dir%%projectsettings% %src%%projectsettings%
在c# 中写调用批处理 批处理文件 duokaipc.bat 方法
#if UNITY_EDITOR
using System;
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEngine;
public static class DuoKaiPro
{
[UnityEditor.MenuItem("Tools/多开PC客户端", false, 0)]
private static void Exe()
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
return;
}
string shell = "duokaipc.bat";
string workingDir = Application.dataPath.Replace("Assets","");
string path = Path.Combine(workingDir, shell);
string proname = Path.GetFileName(Path.GetDirectoryName(path));
workingDir = workingDir.Replace(proname+"/", "");
Process p = new Process();
ProcessStartInfo pi = new ProcessStartInfo(path);//第二个参数为传入的参数,string类型以空格分隔各个参数
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
p.StartInfo = pi;
p.Start();
p.WaitForExit();
}
}
#endif