Last active
August 29, 2015 14:02
-
-
Save leahcim/a08cf4d06f3e129cb18e to your computer and use it in GitHub Desktop.
A simple launcher and batch package importer for the Unity Editor. Download the editor from: http://unity3d.com
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
#!/bin/bash | |
# 11th July 2014 | |
UNITY="C:\Program Files\Unity\Editor\Unity.exe" | |
LOG="Library/ImportedPackages.txt" | |
usage() { | |
cat << EOF | |
A simple launcher and batch package importer for the Unity Editor | |
Download the editor from: http://unity3d.com | |
Usage: | |
$(basename "$0") [-h|-help|--help] | |
$(basename "$0") [PROJECT_PATH] [-i|-import|--import PACKAGE...] | |
When PROJECT_PATH is supplied without flags, start Unity Editor in the | |
specified project path. | |
If PROJECT_PATH is not supplied, assume project is in the current | |
directory. | |
Flags: | |
-help, --help | |
-h Show this help text. Don't start the Unity Editor. | |
-import, --import | |
-i PACKAGE... Run in batch mode and import the packages. | |
This flag and the list of packages must appear as | |
final arguments. Unity Editor is not started. | |
EOF | |
} | |
RED="\e[31m" | |
GREEN="\e[32m" | |
YELLOW="\e[33m" | |
RESET="\e[0m" | |
set_colour() { | |
echo -en $1 | |
} | |
echo_red() { | |
set_colour $RED | |
echo -e $@ | |
set_colour $RESET | |
} | |
echo_yellow() { | |
set_colour $YELLOW | |
echo -e $@ | |
set_colour $RESET | |
} | |
expand_path() { | |
cd "$(dirname "$1")" | |
echo "$PWD/$(basename "$1")" | |
} | |
if [ -d "$1" ]; then | |
proj=$(expand_path "$1") | |
shift | |
else | |
proj="$PWD" | |
fi | |
unity_import() { | |
failed=0 | |
skipped=0 | |
for package in "$@" | |
do | |
echo | |
if [ ! -f "$package" ]; then | |
echo_red "Skipping non-existent package:" | |
echo "$package" | |
((failed++)) | |
continue | |
fi | |
digest=$(md5sum "$package" | cut -d ' ' -f1) | |
# If Log file exists and contains the digest... | |
# -q don't output result | |
# -s don't output errors, e.g. "no such file" | |
if grep -qs "$digest" "$proj/$LOG"; then | |
echo_yellow "Skipping already imported package:" | |
echo "$package" | |
((skipped++)) | |
else | |
echo_yellow "Now importing:" | |
echo "$package" | |
set_colour $RED | |
"$UNITY" -projectPath "$proj" \ | |
-batchmode -quit \ | |
-importPackage "$(expand_path "$package")" && | |
echo "$digest $(basename "$package")" >> "$proj/$LOG" | |
((failed += $?)) | |
set_colour $RESET | |
fi | |
done | |
echo | |
echo -en "Imported: $GREEN$(($# - failed - skipped))$RESET, " | |
echo -en "Skipped: $YELLOW${skipped}$RESET, " | |
echo -e "Failed: $RED${failed}$RESET." | |
exit $failed | |
} | |
run_unity() { | |
cmd.exe //c start "" "$UNITY" -projectPath "$proj" "$@" | |
} | |
args= | |
while [ $# -gt 0 ] | |
do | |
case "$1" in | |
-h | *-help) | |
usage | |
exit 0 | |
;; | |
-i | *-import) | |
shift | |
unity_import "$@" | |
exit $? | |
;; | |
*) | |
args="$args $1" | |
shift | |
;; | |
esac | |
done | |
run_unity "$args" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment