Add your own templates
Example with singleton
Add template to Unity templates folder by selecting ScriptTemplateSettings and clicking on "Edit Script Template" button :
Create a new file and name it 82-C# Singleton Script-NewSingletonBehaviourScript.cs.txt
Open this file and fill it :
///-----------------------------------------------------------------
/// Author : #DEVELOPER_NAME#
/// Date : #DATE#
///-----------------------------------------------------------------
using UnityEngine;
namespace #RELATIVE_NAMESPACE# {
public class #SCRIPTNAME# : MonoBehaviour {
private static #SCRIPTNAME# _instance;
public static #SCRIPTNAME# Instance { get { return _instance; } }
private void Awake(){
if (_instance){
Destroy(gameObject);
return;
}
_instance = this;
}
private void Start () {
#NOTRIM#
}
private void Update () {
#NOTRIM#
}
private void OnDestroy(){
if (this == _instance)
_instance = null;
}
}
}
Unity generates automatically new menu when you add your templates to its resources. (Menus appear after restarting Unity)
Composition of the menu from the file name:82-C# Singleton Script-NewSingletonBehaviourScript.cs.txt
82
: Menu Item position.C# Singleton Script
: Menu nameNewSingletonBehaviourScript.cs
: Default script name
You can also make submenu:
With:82-C# Example__Singleton-NewSingletonBehaviourScript.cs.txt
You will get this result below :
Each __
represent a submenu. You can cumulate them.
Note: If you want create script from template in another location Unity will not create menu but you can add your own MenuItem and use a method in ScriptTemplateUtils to create script.