Skip to content

Instantly share code, notes, and snippets.

@SolidAlloy
Created May 9, 2020 18:00
Show Gist options
  • Save SolidAlloy/2b8f5fd8f562ef83dcf9c48e441977bd to your computer and use it in GitHub Desktop.
Save SolidAlloy/2b8f5fd8f562ef83dcf9c48e441977bd to your computer and use it in GitHub Desktop.
Overwrite Unity default template in one command.
# 1. Change the path to Unity Editors in the path_to_unity variable below.
# 2. Put the template you wish to use in the template_content variable.
# 3. Run a command like this: python unity_dark_theme.py 2019.3.3f1
import sys
if len(sys.argv) != 2:
sys.exit("Provide a Unity version as an argument.")
unity_version = sys.argv[1]
# Change to the path to Unity Editors you are actually using.
path_to_unity = 'c:/Program Files/Unity Editors/{}/Editor'.format(unity_version)
# Change to the template you would like to use.
template_content = '''using UnityEngine;
public class #SCRIPTNAME# : MonoBehaviour
{
}
'''
template_path = sys.path.join(path_to_unity,
'Editor/Data/Resources/ScriptTemplates/81-C# Script-NewBehaviourScript.cs.txt')
try:
with open(template_path, 'w') as template:
template.write(template_content)
except IOError:
sys.exit("No such path to Unity, or this version of Unity is not installed.")
print("Template content overwritten successfully.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment