UnityEditor基礎 建立Lua指令碼模版

2021-08-09 23:03:45 字數 1739 閱讀 3946

unity裡能建立 c#指令碼模板,但是如果我想建立lua指令碼模板怎麼辦呢?拓展一下編輯器吧。

先準備乙個lua指令碼模版檔案,位置例如在:assets/editor/lua/template/lua.lua

c#**:

using unityengine;

using unityeditor;

using system;

using system.io;

using system.text;

using unityeditor.projectwindowcallback;

using system.text.regularexpressions;

public class test

public static string getselectedpatho***llback()

}return path;

}}

class mydocreatescriptasset : endnameeditaction

internal static unityengine.object createscriptassetfromtemplate(string pathname, string resourcefile)

//else

//bool encodershouldemitutf8identifier = true;

bool throwoninvalidbytes = false;

utf8encoding encoding = new utf8encoding(encodershouldemitutf8identifier, throwoninvalidbytes);

streamwriter.write(text);

streamwriter.close();

assetdatabase.importasset(pathname);

return assetdatabase.loadassetatpath(pathname, typeof(unityengine.object));}}

因為是模板,就可以新增一些預製**在上面, 當填寫完類名後可以來替換操作,  例如unity自帶的 建立c#檔案, 外面寫了類名裡面也跟著變。

在project面板右鍵新建:

然後可以輸入lua指令碼的類名。

然後就根據自己建立lua的檔名 正則替換模板裡的東西了:

c#裡的**可以自行擴充套件,多寫幾個選單,使用不同的模版建立不同使用者的lua指令碼,如某介面的ui指令碼,某一塊的資料管理指令碼。

擴充套件:1/ 如也可以在63行左右位置加上text = regex.replace(text, "#time#", system.datetime.today.toshortdatestring());把當前年月日也替換到lua**裡,也可以根據自己的專案的習慣,謝一些模版內容,按需要替換哈。

2/ 可以把projectwindowutil.startnameeditingifprojectwindowexists單獨封裝為乙個方法,傳入string引數作模版路徑,然後根據需要謝不同的menuitem選單去呼叫使用不同的模版建立檔案。

感謝雨松momo大大的教誨。

UnityEditor基礎屬性簡介

space 新增空行 range 在面板上限制乙個數的範圍,方便策劃修改之類 serializefield 使私有變數可以在面板上顯示 textarea 建立乙個多行的文字輸入框 tooltip 滑鼠放上後會彈出提示框 serializable 使乙個類序列化,呼叫這個類時可以在面板上顯示 menu...

編寫 Unity Editor 外掛程式

在開發過程中,我喜歡編寫一些輔助的editor外掛程式,方便在遊戲開發過程進行除錯。下面是摘自asset store的乙個檢視unity 預設gui樣式的小工具 原理 遍歷所有的gui.skin,並顯示其樣式 using unityengine using unityeditor 檢視預設的gui ...

Unity Editor 入門總結 2

1 二進位制序列化 public static bool binaryserilize string path,system.object obj return true catch exception e return false 2 二進位制反序列化 public static t binary...