Skip to content

Instantly share code, notes, and snippets.

@luisparravicini
Last active July 17, 2021 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisparravicini/61e0f95ab7c583fbbd9ce2e79c1a115a to your computer and use it in GitHub Desktop.
Save luisparravicini/61e0f95ab7c583fbbd9ce2e79c1a115a to your computer and use it in GitHub Desktop.
script for automated Unity project builds
#!/bin/bash
#
# This script creates builds for several platforms for a Unity project.
# It assumes this directory hierarchy:
# base_dir/
# UnityProjectName/
# dist/
# dist/files/
#
# dist/ is where this script must be located
# dist/files/ is where extra files included in the build must be located (for example: README files)
# UnityProjectName/ is where the project files are. The name of this folder is located in the file `unity_config`
dir=`dirname "$0"`
config_path="$dir"/unity_config
if [ ! -f "$config_path" ]; then
echo unity config not found at $config_path
exit 1
fi
source "$config_path"
project_path="$dir/../$name/"
function build_player () {
echo
echo building for $platform
platform_dir="$dir"/$platform
rm -rf "$platform_dir"
mkdir -p "$platform_dir"
cp "$dir"/files/* "$platform_dir"/
version=$(grep bundleVersion: "$project_path"/ProjectSettings/ProjectSettings.asset | sed -e 's/[[:blank:]]*bundleVersion:[[:blank:]]*//')
echo version: $version
date=$(date +%Y-%m-%d)
echo "release: $date-r$version" > "$platform_dir"/release.txt
$unity_path -quit -batchmode -projectpath "$project_path" $platform_arg ../dist/$platform/$binary_name
}
echo using unity from $unity_path
echo
if [ ! -x "$unity_path" ]; then
echo Unity not found at $unity_path
exit 1
fi
platform=linux
platform_arg=-buildLinux64Player
binary_name=$name
build_player
platform=macOS
platform_arg=-buildOSXUniversalPlayer
binary_name=$name.app
build_player
platform=windows
platform_arg=-buildWindows64Player
binary_name=$name/$name.exe
build_player
# Replace with your Unity path
#unity_path=/home/user/Unity/Hub/Editor/2021.1.14f1/Editor/Unity
unity_path="/Volumes/ssd0/Applications/Unity/Hub/Editor/2020.1.0b12/Unity.app/Contents/MacOS/Unity"
# The name will be used as a folder name to locate the project base dir
name="NameOfYourProject"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment