Skip to content

Commit

Permalink
update utils
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay committed Jan 22, 2024
1 parent 05c9c57 commit 6652d79
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions script/_utils.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
get_unity_version() {
if [ ! -f "$1/ProjectSettings/ProjectVersion.txt" ]; then
echo "error: $1/ProjectSettings/ProjectVersion.txt not found" >&2
exit 1
fi
echo $(cat "$1/ProjectSettings/ProjectVersion.txt" | grep m_EditorVersion: | sed 's/m_EditorVersion: //g')
echo $(cat $1/ProjectSettings/ProjectVersion.txt | grep m_EditorVersion: | sed 's/m_EditorVersion: //g')
}

get_unity_path() {
local unity_version=$1
local unity_path=$(find /Applications/Unity/Hub/Editor -type d -name "$unity_version*" | sort -r | head -n 1)
echo $unity_path
if ${docker:-false}; then
# When in docker mode, the version number is all we need
echo $unity_version
else
local unity_path=$(find /Applications/Unity/Hub/Editor -type d -name "$unity_version*" | sort -r | head -n 1)
echo $unity_path
fi
}

get_build_type() {
Expand All @@ -21,8 +22,55 @@ get_build_type() {

}

unity_docker() {
local unity_version="$1"
shift
local executable="$1"
shift

docker_image="unityci/editor:ubuntu-${unity_version}-linux-il2cpp-3"
echo "Using docker Unity $docker_image ..."
docker run \
--rm \
-v "${repo_root}:/project" \
-w /project \
--platform linux/amd64 \
--env unity_path="/opt/Unity/Editor" \
--env UNITY_DOCKER=1 \
--env UNITY_LICENSE \
--env UNITY_SERIAL \
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
"$docker_image" \
"$executable" \
"$@"
}

unity() {
local unity_path="$1"
shift
"$unity_path/Unity.app/Contents/MacOS/Unity" "$@"

if [ "${UNITY_DOCKER:-}" = "1" ]; then
# Activate Unity First
activation_args=()
[ -n "${UNITY_SERIAL:-}" ] && activation_args+=(-serial "${UNITY_SERIAL}")
[ -n "${UNITY_EMAIL:-}" ] && activation_args+=(-username "${UNITY_EMAIL}")
[ -n "${UNITY_PASSWORD:-}" ] && activation_args+=(-password "${UNITY_PASSWORD}")

echo "*** ACTIVATING UNITY LICENSE ***"
/usr/bin/xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
/usr/bin/unity-editor \
-logFile /dev/stdout \
-batchmode \
-nographics \
"${activation_args[@]}"
fi


echo "Using Unity at $unity_path ..."
if [ "$(uname)" == "Darwin" ]; then
"$unity_path/Unity.app/Contents/MacOS/Unity" "$@"
else
"$unity_path/Unity" "$@"
fi
}

0 comments on commit 6652d79

Please sign in to comment.