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

猜你喜欢

转载自blog.csdn.net/weixin_44806700/article/details/126305868
今日推荐