Skip to content

Instantly share code, notes, and snippets.

@mob-sakai
Last active May 30, 2023 21:29
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 mob-sakai/c6e1a5362bc6237cfc9caafaf02e1de4 to your computer and use it in GitHub Desktop.
Save mob-sakai/c6e1a5362bc6237cfc9caafaf02e1de4 to your computer and use it in GitHub Desktop.

Unity CLI Tools (macOS)

Installation

curl -sL https://gist.githubusercontent.com/mob-sakai/c6e1a5362bc6237cfc9caafaf02e1de4/raw/unity.sh >> ~/.zprofile

Usage

Run Unity (batch mode, in Unity project dir):

  • with specified version: unity-run <version> -- [args...]
  • with ProjectVersion.txt: unity-run [args...]

List available Unity versions (installed with UnityHub):

  • unity-list

Decompile Unity with specified version:

  • unity-decompile <version>
#unity cli tools
unity-list(){
echo "* Available versions:"
ls -1 /Applications/Unity/Hub/Editor
}
unity-run(){
help()
{
echo "Run Unity with specified version: unity-run <version> -- [args...]"
echo "Run Unity with ProjectVersion.txt: unity-run [args...]"
unity-list
}
[ "$1" = "" ] || [ "$1" = "-h" ] && help && return 0
[ ! -d 'Assets' ] && echo 'Current directory is not an Unity project.' && return 1
if [ "$2" = "--" ]; then
/Applications/Unity/Hub/Editor/$1/Unity.app/Contents/MacOS/Unity -batchmode -projectPath . ${@:3}
elif [ -e ProjectSettings/ProjectVersion.txt ]; then
VERSION=`sed -n 's/^m_EditorVersion: //p' ProjectSettings/ProjectVersion.txt`
/Applications/Unity/Hub/Editor/$VERSION/Unity.app/Contents/MacOS/Unity -batchmode -projectPath . $@
else
help
return 1
fi
}
unity-decompile(){
help()
{
echo "Decompile Unity with specified version: unity-decompile <version>"
unity-list
}
[ "$1" = "" ] || [ "$1" = "-h" ] && help && return 0
VERSION=$1
MANAGED_DIR="/Applications/Unity/Hub/Editor/$1/Unity.app/Contents/Managed"
[ ! -d "$MANAGED_DIR" ] && echo 'Not available version' && return 1
[ ! -d "~/UnityDecompiled" ] && mkdir "~/UnityDecompiled"
[ ! -d "~/UnityDecompiled/$1" ] && mkdir "~/UnityDecompiled/$1"
DLLS=($MANAGED_DIR/*.dll)
for DLL in "${DLLS[@]}"
do
DIR=~/UnityDecompiled/$1/`basename "$DLL" .dll`
mkdir "$DIR"
ilspycmd -p -o "$DIR" "$DLL"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment