Entrance
Open the plugin folder to see
LuaAPI can be downloaded from GitHub
https://github.com/fairygui/FairyGUI-Editor/tree/master/plugin/LuaAPI
main.lua
The entry point after the plugin is executed is this main.lua,
onPublish
Define the following method in main.lua, this global method will be called when you publish
function onPublish(handler)
print_re("Test release onPublish", handler)
loge("handler.pkg.name=" ... handler.pkg. name)
end
Handler type: CS.FairyEditor.PublishHandler
can use this to do some operations, such as creating codes together when publishing
Custom Inspector
You can create a custom package in the FGUI editor, and then publish
Create a lua table in main.lua,
the main key value:
create(): When this plugin is executed and the inspector is created, the method
updateUI( ): This method will be called when the UI panel changes.
Create this custom panel in create(), and then follow your own logic.
CS.FairyGUI.UIPackage.CreateObject(packageName, resName);
App.inspectorView:AddInspector(inspector, "Custom Panel", "Custom Panel");
App.docFactory:ConnectInspector("Custom Panel", "mixed", false, false);
App.pluginManager:LoadUIPackage(PluginPath…‘/aaa-CustomInspector’)
Some APIs (continuously updated)
console output
fprint(""); ordinary log
App.consoleView:LogWarning(mes); warning output
App.consoleView:LogError(str, error); output error, error can be empty, the type is CS.System.Exception
App.activeDoc: the currently open page
inspectingTargets, get all selected objects in the current interface (FairyEditor.FObject)
InsertObject: Create built-in components, such as GTextField: InsertObject("text");
PluginPath
The output is the absolute path of plugins
App.docFactory:
ConnectInspector
Connect this custom Inspector
parameters inspectorName, forObjectType, forEmptySelection, forTimelineMode
forTimelineMode: bool - whether to display in TimeLine
App.RefreshProject(); //Refresh the project
System.IO //File or directory operation System starts with C# API
main menu extension
App.mainView.toolbar------This is a GComponent type. You
can create a GObject through the combination of
App.pluginManager:LoadUIPackage(path)
CS.FairyGUI.UIPackage.CreateObject(name, resName)
and add it to the toolbar
hot key
App.pluginManager.SetHotKey("CTRL+S", callback)
Right-click menu App.libView.contextMenu
The right-click menu of a specific resource in the resource library
App.libView.contextMenu:AddItem(“libView”, “libView”, function()
fprint(“haha”)
end);
The right-click menu of the display list, the right-click menu of the stage, the right-click menu of the stage component
App.docFactory.contextMenu:AddItem(“docFactory”, “docFactory”, function()
fprint(“docFactory”)
end);
top menu bar
var menu = App.menu:GetSubMenu(“tool”)
menu:AddItem(“display name”, “name”, atIndex, isSubMenu, (name) => { fprint(“press”); });
function onDestroy() {
menu.RemoveItem(“name”);
}
//FPackageItem to FObject
FairyEditor.FObjectFactory.CreateObject
//Create a component FPackageItem
var targetItem = targetPackage.CreateComponentItem("Bubble", 600, 100, "/", "", true, true)
//FPackageItem is instantiated as FComponent
var rootNode = FairyEditor.FObjectFactory.CreateObject(targetItem) as FairyEditor.FComponent
…
//Add pictures and text nodes
rootNode.AddChild(image)
and write them into XML
rootNode.Write_editMode