Skip to content

Instantly share code, notes, and snippets.

@v01pe
Created October 23, 2018 13:34
Show Gist options
  • Save v01pe/5eeaf56d5acb419d64e654799458e118 to your computer and use it in GitHub Desktop.
Save v01pe/5eeaf56d5acb419d64e654799458e118 to your computer and use it in GitHub Desktop.
Replace and add custom script templates for Unity
#!/bin/bash
#locating unity folder
if [ "$#" -gt 0 ]
then
unityFolder=${1%/}
else
unityFolder="/Applications/Unity"
fi
originalTemplatePath="$unityFolder/Unity.app/Contents/Resources/ScriptTemplates"
if [ ! -d "$originalTemplatePath" ]
then
echo "Could not find script templates at '$originalTemplatePath'"
exit 0
fi
customTemplatePath="`dirname "$0"`/unity templates"
originalTemplateBackupFile="$originalTemplatePath/backup.zip"
#create template backup folder
if [ ! -f "$originalTemplateBackupFile" ]
then
echo "Making backup of original templates"
# (cd "$originalTemplatePath"; pwd; zip -r "$originalTemplateBackupFile" *.txt)
zip -j -0 "$originalTemplateBackupFile" "$originalTemplatePath/"*.txt
fi
#replacing with custom templates
for customTemplateFile in "$customTemplatePath/"*.txt
do
templateFileName=`basename "$customTemplateFile"`
originalTemplateFile="$originalTemplatePath/$templateFileName"
#override original with custom template
if [ -f "$originalTemplateFile" ]
then
echo "overriding: $originalTemplateFile"
else
echo "adding: $originalTemplateFile"
fi
cp -f "$customTemplateFile" "$originalTemplateFile"
done
@v01pe
Copy link
Author

v01pe commented Oct 23, 2018

Manual (This only works on OS X):

  • To use this, you need a folder next to the script called unity templates. Inside this folder you have your custom scripts. If you want to replace built in scripts, name them the same as the original ones.
  • If you moved your Unity folder, you can pass it in as argument.
  • When executing the script for the first time, a backup .zip file is made in the templates folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment