You can create a C # script template in unity, but what if I want to create a LUA scripting template? Expand the editor.
Set the template for the Lua script address: Assets/editor/lua/template/lua.lua
usingUnityengine;usingUnityeditor;usingSystem;usingSystem.IO;usingSystem.Text;usingUnityeditor.projectwindowcallback;usingSystem.Text.RegularExpressions; Public classtest{[MenuItem ("Assets/create/lua Script",false, the)] Public Static voidCreatnewlua () {projectwindowutil.startnameeditingifprojectwindowexists (0, Scriptableobject.createinstance<MyDoCreateScriptAsset>(), Getselectedpathorfallback ()+"/new Lua.lua", NULL, "Assets/editor/lua/template/lua.lua"); } Public Static stringGetselectedpathorfallback () {stringPath ="Assets"; foreach(Unityengine.object objinchSelection.getfiltered (typeof(Unityengine.object), selectionmode.assets)) {Path=Assetdatabase.getassetpath (obj); if(!string. IsNullOrEmpty (PATH) &&file.exists (path)) {Path=Path.getdirectoryname (Path); Break; } } returnpath; }} classmydocreatescriptasset:endnameeditaction{ Public Override voidAction (intInstanceId,stringPathName,stringresourcefile) {Unityengine.object o=createscriptassetfromtemplate (PathName, resourcefile); Projectwindowutil.showcreatedasset (o); } Internal StaticUnityengine.object Createscriptassetfromtemplate (stringPathName,stringresourcefile) { stringFullPath =Path.GetFullPath (pathName); StreamReader StreamReader=NewStreamReader (resourcefile); stringText =Streamreader.readtoend (); Streamreader.close (); stringFilenamewithoutextension =path.getfilenamewithoutextension (pathName); Text= Regex.Replace (Text,"#NAME #", filenamewithoutextension); //string text2 = Regex.Replace (Filenamewithoutextension, "", String. Empty); //Text = regex.replace (text, "#SCRIPTNAME #", Text2); //if (char. Isupper (Text2, 0))//{ //Text2 = char. ToLower (text2[0]) + Text2. Substring (1); //Text = regex.replace (text, "#SCRIPTNAME_LOWER #", Text2); //} //Else//{ //Text2 = "my" + char. ToUpper (text2[0]) + Text2. Substring (1); //Text = regex.replace (text, "#SCRIPTNAME_LOWER #", Text2); //} BOOLEncodershouldemitutf8identifier =true; BOOLthrowOnInvalidBytes =false; UTF8Encoding encoding=Newutf8encoding (Encodershouldemitutf8identifier, throwOnInvalidBytes); BOOLAppend =false; StreamWriter StreamWriter=NewStreamWriter (FullPath, append, encoding); StreamWriter.Write (text); StreamWriter.Close (); Assetdatabase.importasset (PathName); returnAssetdatabase.loadassetatpath (PathName,typeof(Unityengine.object)); } }
Because it is a template can add some prefabricated code on the above, when the class name can be completed after the replacement operation, such as unity to create a C # file, the outside of the class name is also changed. Lua Script creat
You can then enter the class name of the Lua script
It then replaces the contents of the template with the file name of the Lua you created.
- This article fixed link: http://www.xuanyusong.com/archives/3732
"Turn" Unity3d Academy Editor create LUA script template