c# - Unity Add Default Namespace to Script Template? -
i got question. found unitys script template c# scripts. , script name write #scriptname#
looks this:
using unityengine; using system.collections; public class #scriptname# : monobehaviour { void start () { } void update () { } }
than create script right name, there somthing #foldername# can put in right namespace dirrectly when creating script?
there no built-in template variables #foldername#.
according this post, there 3 magic variables.
- "#name#"
- "#scriptname#"
- "#scriptname_lower#"
but can hook creation process of script , append namespace using assetmodificationprocessor
.
here example adds custom data created script.
//assets/editor/keywordreplace.cs using unityengine; using unityeditor; using system.collections; public class keywordreplace : unityeditor.assetmodificationprocessor { public static void onwillcreateasset ( string path ) { path = path.replace( ".meta", "" ); int index = path.lastindexof( "." ); 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; file = system.io.file.readalltext( path ); file = file.replace( "#creationdate#", system.datetime.now + "" ); file = file.replace( "#projectname#", playersettings.productname ); file = file.replace( "#smartdevelopers#", playersettings.companyname ); system.io.file.writealltext( path, file ); assetdatabase.refresh(); } }
Comments
Post a Comment