Talstra

Talstra

Shifting Focus...

Array

Batch Scripts 

Check Unity And Download Version

Estimated reading: 4 minutes 99 views Contributors
@echo off
setlocal

REM Check if Unity 2022.2.18 is already installed
if not exist “C:\Program Files\Unity\Hub\Editor\2022.3.8f1\Editor\Unity.exe” (
echo Unity 2022.2.18 is not installed. Downloading…

REM Download Unity 2022.2.18 installer using curl
curl -o "UnityInstaller.exe" "https://download.unity3d.com/download_unity/5ebc6493a86f/Windows64EditorInstaller/UnitySetup64-2022.2.18f1.exe"

REM Run the installer (modify the path as needed)
start /wait UnityInstaller.exe /S

REM Clean up the installer
del UnityInstaller.exe
) else (
echo Unity 2022.2.18 is already installed.
)

REM Uninstall Unity Hub
“C:\Program Files\Unity Hub\Uninstall Unity Hub.exe” /S

REM Create MyUnityProject folder
mkdir “%USERPROFILE%\Documents\MyUnityProject”

REM Run Unity Editor
“C:\Program Files\Unity\Hub\Editor\2022.3.8f1\Editor\Unity.exe”

endlocal

@echo off: This command turns off the echoing of commands in the command prompt window. It ensures that only the output of the commands is displayed, making the execution cleaner.

  • setlocal: This command starts localization of environment changes in the batch file. It ensures that any changes made to the environment variables are local to the batch file and won’t affect the rest of the system after the batch file execution completes.


Explanation:

Let’s break down the provided batch script line by line:

batchCopy code@echo off
setlocal
  • @echo off: This command turns off the echoing of commands in the command prompt window. It ensures that only the output of the commands is displayed, making the execution cleaner.
  • setlocal: This command starts localization of environment changes in the batch file. It ensures that any changes made to the environment variables are local to the batch file and won’t affect the rest of the system after the batch file execution completes.

REM: This is a remark or comment in the script, used for documentation purposes. It’s not executed as a command.

  • @echo off: This command turns off the echoing of commands in the command prompt window. It ensures that only the output of the commands is displayed, making the execution cleaner.
  • setlocal: This command starts localization of environment changes in the batch file. It ensures that any changes made to the environment variables are local to the batch file and won’t affect the rest of the system after the batch file execution completes.
  • if not exist "C:\Program Files\Unity\Hub\Editor\2022.3.8f1\Editor\Unity.exe": This checks if Unity 2022.2.18 is not installed by verifying the existence of the Unity executable file. If it’s not found, the subsequent commands within the parentheses are executed.
  • echo Unity 2022.2.18 is not installed. Downloading…: This displays a message indicating that Unity 2022.2.18 is not installed, and the downloading process is initiated.
  • curl -o "UnityInstaller.exe" "https://download.unity3d.com/download_unity/5ebc6493a86f/Windows64EditorInstaller/UnitySetup64-2022.2.18f1.exe": This command downloads the Unity 2022.2.18 installer using the curl utility.
  • start /wait UnityInstaller.exe /S: This command starts the UnityInstaller.exe with the /S switch, which installs Unity silently without user interaction. The /wait flag ensures that the script waits for the installer process to finish before proceeding.
  • del UnityInstaller.exe: This command deletes the UnityInstaller.exe file after the installation is complete.
  • else: If Unity 2022.2.18 is already installed, the script executes the commands within the parentheses.
  • echo Unity 2022.2.18 is already installed.: This displays a message indicating that Unity 2022.2.18 is already installed.

Practical Application:

This batch script automates several tasks related to managing Unity installations and projects:

  1. It checks if Unity 2022.2.18 is installed and installs it if not.
  2. It uninstalls Unity Hub.
  3. It creates a folder named “MyUnityProject” in the user’s Documents directory.
  4. It runs the Unity Editor.

You can save this script in a .bat file and run it to automate the setup process for Unity development. Just ensure to modify the paths and version numbers as needed for your environment.

Share this Doc

Check Unity And Download Version

Or copy link

CONTENTS
Chat Icon Close Icon