I found template files in “[Unity-installation-folder]\Editor\Data\Resources\ScriptTemplates” and edited 81-C# Script-NewBehaviourScript.cs.txt file as I wish (Note: Use for example Notepad++ as administrator for editing).
Now I want to add Current Date, Developer Name, Project Name and other project corresponding data by default. Can someone post full list of available Key Vars (like we have now #SCRIPTNAME#)?
I don’t think there are any other magic variables that get processed in those templates…
Another option - you can create new templates. For example, if you put a new file in that folder named “85-C# Singleton Script-NewBehaviourScript.cs.txt” then you would get a new menu option in the editor for Create->C# Singleton Script (Note - Unity needs to be restarted to recognize new templates). In your case you could maybe make a template for each project to get what you want? Not a great solution though…
You should maybe also check out the free Create Script Dialog package in the asset store here:
You could probably extend that package to do what you want fairly easily.
Great Post, hpjohn. I know, this thread is old, but I thought, I’d revive it to fix the code snippet, as it is one of the first and best results for certain searches.
The two new return-statements are important for not causing exceptions when Folder-Assets named WhatEver (first return condition) or WhatEver.cs (third return condition) are added to the project.
public static void OnWillCreateAsset (string path) {
path = path.Replace( ".meta", "" );
int index = path.LastIndexOf( "." );
if (index < 0)
return;
string file = path.Substring( index );
if (file != ".cs" && file != ".js" && file != ".boo")
return;
index = Application.dataPath.LastIndexOf( "Assets" );
path = Application.dataPath.Substring( 0, index ) + path;
if (!System.IO.File.Exists( path ))
return;
string fileContent = System.IO.File.ReadAllText( path );
fileContent = fileContent.Replace( "#AUTHOR#", AuthorName );
fileContent = fileContent.Replace( "#NAMESPACE#", GetNamespaceForPath(path) );
System.IO.File.WriteAllText( path, fileContent );
AssetDatabase.Refresh();
}
WOW… just recently stumbled upon the ability to create own script templates.
AWESOME script the you guys wrote! helped me so so much to make the templates even more useful!
THANKS a lot!
@hgeghamyan@Marc_Zaku I’ve slightly improved script template to make it more automate. There is no need to edit something in script anymore, just edit special setting txt file and add templates in special folder : )
I’ve described it in my blog, check out.