Created
November 29, 2017 16:05
-
-
Save bendangelo/dcb58752afc14b0f4e7e84f9801e3c61 to your computer and use it in GitHub Desktop.
OSX script to build unity games.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HELP=" | |
################################################# | |
# # | |
# UnityBuildAll # | |
# # | |
################################################# | |
# A simple script by SnowHydra # | |
# # | |
# Automated building of your Unity app # | |
# To Windows, Mac, Linux. # | |
# # | |
# Do what you want with this script # | |
# But be nice. # | |
# Like, don't just change SnowHydra to you. # | |
# # | |
# snowhydra.com # | |
################################################# | |
################################################# | |
# USAGE INSTRUCTIONS # | |
################################################# | |
# # | |
# !!IMPORTANT!! # | |
# Close Unity before running! # | |
# # | |
# Run the command: # | |
# UnityBuildAll appname targetdir [readmefile] # | |
# # | |
# for example: # | |
# UnityBuildAll Zarvot ~/ZarvotBuild # | |
# # | |
# You may also define a readme file. # | |
# UnityBuildAll Zarvot ~/Build ~/readme.txt # | |
# # | |
# By default, it will look for a readme file # | |
# inside your build folder. # | |
# That is, next to the Mac, Windows folders. # | |
# # | |
################################################# | |
" | |
#!/bin/bash | |
#default stuff. you can change this if you want | |
#change allowdefault to true, then you can just | |
#run without args, and it'll use your APPNAME | |
ALLOWDEFAULT=false | |
APPNAME="Zarvot" | |
DIRECTORY="${HOME}/UnityBuilds/${APPNAME}" | |
################################################# | |
# check number of args | |
#help | |
if [ "$1" == "--help" ]; then | |
echo "$HELP" | less | |
exit 0 | |
fi | |
#check arg count, throw errors | |
if [ ! $ALLOWDEFAULT -o $# -le 1 ]; then | |
echo "usage: UnityBuildAll app_name [target_dir] [readme_file]" | |
echo "(\"UnityBuildAll --help\" for help.)" | |
exit 0 | |
fi | |
#command line arg for appname | |
if [ $# -ge 1 ]; then | |
APPNAME=$1 | |
fi | |
#command line arg for dir | |
if [ $# -ge 2 ]; then | |
DIRECTORY=$2 | |
fi | |
#the readme file to include | |
README="${DIRECTORY}/readme.txt" | |
#command line arg for readme | |
if [ $# -ge 3 ]; then | |
README=$3 | |
fi | |
################################################# | |
# setup | |
echo "Creating directories." | |
#will make all the req directories | |
mkdir -p ${DIRECTORY}/Mac | |
mkdir -p ${DIRECTORY}/Windows/${APPNAME} | |
mkdir -p ${DIRECTORY}/Linux/${APPNAME} | |
mkdir -p ${DIRECTORY}/Archives | |
#copy readme to each folder if it exists | |
if [ -f $README ]; then | |
echo "Copying readme file." | |
cp $README ${DIRECTORY}/Mac | |
cp $README ${DIRECTORY}/Windows | |
cp $README ${DIRECTORY}/Linux | |
cp $README ${DIRECTORY}/Archives | |
fi | |
################################################# | |
# unity build command | |
LOGFILE="${DIRECTORY}/UnityBuildLog.txt" | |
UNITY="/Applications/Unity/Unity.app/Contents/MacOS/Unity" | |
OSX="${DIRECTORY}/Mac/${APPNAME}.app" | |
WIN="${DIRECTORY}/Windows/${APPNAME}/${APPNAME}.exe" | |
LIN="${DIRECTORY}/Linux/${APPNAME}/${APPNAME}" | |
FLAGS="-quit -batchmode -logfile ${LOGFILE}" | |
#run the command | |
echo "Building Mac..." | |
$UNITY $FLAGS -buildOSXPlayer $OSX | |
echo "Building Windows..." | |
$UNITY $FLAGS -buildWindowsPlayer $WIN | |
echo "Building Linux..." | |
$UNITY $FLAGS -buildLinuxUniversalPlayer $LIN | |
################################################# | |
# zip that stuff up | |
echo "Creating archives..." | |
#pushes directories up the 'stack' | |
#piping to > /dev/null to suppress messages | |
pushd ${DIRECTORY}/Linux > /dev/null | |
pushd ${DIRECTORY}/Windows > /dev/null | |
pushd ${DIRECTORY}/Mac > /dev/null | |
#zip then pop the next one | |
zip -r ${DIRECTORY}/Archives/${APPNAME}\(Mac\) * >> ${LOGFILE} | |
popd > /dev/null | |
zip -r ${DIRECTORY}/Archives/${APPNAME}\(Windows\) * >> ${LOGFILE} | |
popd > /dev/null | |
zip -r ${DIRECTORY}/Archives/${APPNAME}\(Linux\) * >> ${LOGFILE} | |
popd >/dev/null | |
echo "Done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment