.bat批处理程序一键启动Unity工程

前言

承接上篇文章UE4的启动方式,这里也做了一个关于Unity的项目启动,谁叫曾经我是Unity吹,那就也做一个吧。
在这里插入图片描述

放出代码:固定一个版本启动

@echo off
set Editor=需要自行设置编辑编辑器exe路径
echo Unity编辑器路径==%Editor%
start %Editor% -projectPath %~dp0

放出代码:多版本选择启动(Unity_5.6.7f1、Unity_2018.4.0f1示例)

@echo off
set Unity_0=D:\Software_learn\Unity\UnityEditor\5.6.7f1
set Unity_1=D:\Software_learn\Unity\UnityEditor\2018.4.0f1
set EditorPath=\Editor\Unity.exe

echo "==========请输入↓============"
echo 输入0——%Unity_0%
echo 输入1——%Unity_1%
echo "================================"

:重新选择
set /p input=请输入数字执行:

if %input% == 0 (
set Editor=%Unity_0%%EditorPath%
) else if %input% == 1 (
set Editor=%Unity_1%%EditorPath%
) else (
echo 选择错误!请重新选择↑
goto 重新选择
)

echo "======================"
echo "当前项目打开引擎:"%Editor%
echo "======================"

echo %~dp0
start %Editor% -projectPath %~dp0
pause

注意事项

Unity的启动方式是编辑器exe打开Assets上层目录(即工程目录),使用时请将编辑器的路径修改成你的Unity编辑器路径。当然这个bat文件要放到Assets文件同级目录下,和UE不同的是start命令编辑器之后要加-projectPath,不然他会只打开unity编辑器,这样就不够自动化。

批处理文件如果不能使用中文请将文件编码设置为:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42541751/article/details/120397540