FGUI编辑器插件开发(不推荐使用,当做参考吧)
入口
打開插件文件夾可以看到
可以從GitHub上下載LuaAPI
https://github.com/fairygui/FairyGUI-Editor/tree/master/plugin/LuaAPI
main.lua
插件執行后的入口就是這個main.lua,
onPublish
在main.lua中定義下面這個方法,當你發布的時候會調用這個全局方法
function onPublish(handler)
print_re(“測試發布onPublish”, handler)
loge(“handler.pkg.name=” … handler.pkg.name)
end
handler的類型:CS.FairyEditor.PublishHandler
利用這個可以做一些操作,比如發布的時候連代碼一起創建出來
自定義Inspector
可以現在FGUI編輯器中創建一個自定義的包,然后發布
在main.lua中創建一個lua table,
主要鍵值:
create():當這個這個插件執行后并且inspector創建后會自動執行該方法
updateUI():當UI面板發生變化時都會調用該方法
在create()中將這個自定義面板創建出來,之后走自己的邏輯即可
CS.FairyGUI.UIPackage.CreateObject(packageName, resName);
App.inspectorView:AddInspector(inspector, “自定義面板”, “自定義面板”);
App.docFactory:ConnectInspector(“自定義面板”, “mixed”, false, false);
App.pluginManager:LoadUIPackage(PluginPath…‘/aaa-CustomInspector’)
一些API(持續更新)
控制臺輸出
fprint(“”);普通log
App.consoleView:LogWarning(mes);警告輸出
App.consoleView:LogError(str, error);輸出報錯,error可為空,類型為CS.System.Exception
App.activeDoc:當前打開的頁面
inspectingTargets,獲取當前界面中的選中所有對象(FairyEditor.FObject)
InsertObject:創建內置組件,比如GTextField:InserObject(“text”);
PluginPath
輸出的是plugins這個絕對路徑
App.docFactory:
ConnectInspector
連接這個自定義Inspector
參數inspectorName, forObjectType, forEmptySelection, forTimelineMode
forTimelineMode:bool — 是否在TimeLine中顯示
App.RefreshProject(); //刷新工程
System.IO //文件or目錄操作 System開頭的都是C#API
主菜單擴展
App.mainView.toolbar------這個是GComponent類型
可以通過
App.pluginManager:LoadUIPackage(path)
CS.FairyGUI.UIPackage.CreateObject(name, resName)
組合創建一個GObject出來,加入toolbar中去
快捷鍵
App.pluginManager.SetHotKey(“CTRL+S”, 回調)
右鍵菜單App.libView.contextMenu
資源庫中具體某個資源的右鍵菜單
App.libView.contextMenu:AddItem(“libView”, “libView”, function()
fprint(“haha”)
end);
顯示列表的右鍵菜單,舞臺右鍵菜單,舞臺元件右鍵菜單
App.docFactory.contextMenu:AddItem(“docFactory”, “docFactory”, function()
fprint(“docFactory”)
end);
頂部菜單欄
var menu = App.menu:GetSubMenu(“tool”)
menu:AddItem(“display name”, “name”, atIndex, isSubMenu, (name) => {
fprint(“按下”);
});
function onDestroy() {
menu.RemoveItem(“name”);
}
//FPackageItem 轉 FObject
FairyEditor.FObjectFactory.CreateObject
//創建一個組件 FPackageItem
var targetItem = targetPackage.CreateComponentItem(“Bubble”, 600, 100, “/”, “”, true, true)
//FPackageItem實例化為FComponent
var rootNode = FairyEditor.FObjectFactory.CreateObject(targetItem) as FairyEditor.FComponent
…
//添加圖片、文本節點
rootNode.AddChild(image)
寫入XML中
rootNode.Write_editMode
總結
以上是生活随笔為你收集整理的FGUI编辑器插件开发(不推荐使用,当做参考吧)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: URL结构分析
- 下一篇: 从零开始学习Node.js例子七 发送H