diff options
Diffstat (limited to 'unity-editor-vrchat')
-rwxr-xr-x | unity-editor-vrchat | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/unity-editor-vrchat b/unity-editor-vrchat new file mode 100755 index 000000000000..d068ad203bf5 --- /dev/null +++ b/unity-editor-vrchat @@ -0,0 +1,64 @@ +#!/bin/sh + +unityhub_editors_path="$HOME/.config/UnityHub" +unityhub_editors_json="$unityhub_editors_path/editors.json" + +check_jq() { + hash jq 2> /dev/null + if [ $? -ne 0 ]; then + echo "ERROR: You need to install 'jq' to register/deregister %PKGNAME% with unithub" + exit 1 + fi +} + +check_unityhub() { + local unityhub_pids=$(pgrep unityhub) + if [ ! -z "$unityhub_pids" ]; then + echo "ERROR: Can't UnityHub config while it's running. Close all Unity/UnityHub processes and try again." + exit 1 + fi +} + +ensure_json() { + if [ ! -f "$unityhub_editors_json" ] || [ ! -s "$unityhub_editors_json" ]; then + mkdir -p "$unityhub_editors_path" + echo "{}" > "$unityhub_editors_json" + fi +} + +unityhub_remove() { + local oldentries=$(cat "$unityhub_editors_json" \ + | jq 'to_entries[] | select(.value.location == ["/usr/bin/%PKGNAME%"]) | [.key?]' \ + | jq -cs '.') + cat "$unityhub_editors_json" | jq -c "delpaths($oldentries)" > /tmp/editors.json + mv /tmp/editors.json "$unityhub_editors_json" +} + +unityhub_add() { + unityhub_remove + cat "$unityhub_editors_json" | jq -c ". + {\"%PKGVER%\":{version:\"%PKGVER%\",location:[\"/usr/bin/%PKGNAME%\"],manual:true}}" > /tmp/editors.json + mv /tmp/editors.json "$unityhub_editors_json" +} + +if [ "$1" == "--register" ]; then + check_jq + check_unityhub + ensure_json + unityhub_add + exit 0 +elif [ "$1" == "--deregister" ]; then + check_jq + check_unityhub + ensure_json + unityhub_remove + exit 0 +fi + +# This prevents the editor from crashing when opening projects in some systems +unset GTK_IM_MODULE + +# HACK: fixes WebGL builds by adding a symlink (python -> python2) to the PATH +export PATH=/opt/Unity/Editor:$PATH + +mkdir -p ~/.local/share/unity3d/Packages +exec /opt/Unity/Editor/Unity -no-throttle-updates "$@" |