I'm familiar with the ability to change script template for Unity game engine. However, it is very limited and only allows one keyword: #SCRIPTNAME#
.
As project gets more and more complicated, namespaces becomes crucial part. And there's no way to have script generated with appropriate namespace through Create --> C# Script
.
Does anyone know any solutions to this?
P.S. I am aware that you can create files with Visual Studio, that automatically get namespace based on location. However, they contain unnecessary parts like Assets.Scripts
...
Doing some research online I've found that you can create
AssetModificationProcessor
withpublic static void OnWillCreateAsset(string path)
method. In this method you can read created script file and replace content usingstring.Replace
(or other methods).Dwelling deeper into this, I've came with useful Editor script that changes
#NAMESPACE#
keyword based on script location in the project (all made using my current project structure, so you might need to adjust the script before it works correctly).In case the link is broken, here's the editor script:
After adding this script under folder named
Editor
, you need to change c# script template which is located at%EditorPath%/Data/Resources/ScriptTemplates/81-C# Script-NewBehaviourScript.cs.txt
. Open this file and add wrap class with