@echo off
chcp 65001

for /f "usebackq tokens=*" %%i in (`cd`) do @set current_dir=%%i

set unity_exe=C:\Program Files\Unity\Hub\Editor\2018.4.2f1\Editor\Unity.exe
set project_path=%current_dir%\MyApp\
set output_path=%current_dir%\Release\
set output_file=%current_dir%\Release\MyApp.exe

echo project_path=%project_path%
echo output_path=%output_path%

if not exist "%unity_exe%" (
	echo %unity_exe% does not exist
	pause
	exit
)

if not exist "%output_path%" (
	echo Make release directory
	mkdir "%output_path%"
)

echo build start
"%unity_exe%" -batchmode -projectPath "%project_path%" -buildWindowsPlayer "%output_file%" -quit

if "%ERRORLEVEL%" == "0" (
	echo "build succeeded"
) else (
	echo build failed : %ERRORLEVEL%
)

pause