"Turn" Unity3d Academy Editor create LUA script template

Source: Internet
Author: User
Tags lua

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.