C# plugin SDK
Kroys.Plugins: commands, panels, settings pages, importers, exporters, asset types, viewport tools, background tasks and undoable scene edits for editor plugins written in C#.
A plugin
Derive one class from EditorPlugin and register what the plugin adds in OnLoad through Host. Save the file and the running editor rebuilds and reloads the plugin. Start with Your first C# plugin.
Plugin.cs
public sealed class LevelToolsPlugin : EditorPlugin { private int clicks; public override void OnLoad() { Host.AddPanel(new PanelOptions("Main", "Level Tools") { Icon = "plug" }, DrawPanel); } private void DrawPanel(Ui ui) { ui.Heading("Level Tools"); if (ui.Button("Count", ButtonStyle.Primary)) clicks++; ui.SameLine(); ui.Text($"Clicks: {clicks}"); } }
Rules the editor relies on
- Every callback runs on the editor's main thread, except importers, exporters and the
runpart ofRunTask(worker threads).LogandPostare thread-safe. - What a plugin uses is declared in its manifest:
capabilitylines (commands, panels, settings, importers, exporters, asset-types, viewport-tools, tasks, services, automation, components) andpermissionlines (scene.read, scene.write, assets.write). A call outside them throwsKroysExceptionnaming the missing line. - An exception that escapes a callback is caught by the editor: the Console shows it with file and line, the plugin turns Faulted until it is reloaded, and the editor keeps running.
- A hot reload removes every registration, calls
OnUnload, unloads the old assembly and callsOnLoadon a new instance. Fields start fresh;GetSetting/SetSettingvalues stay. - Edits of the document scene are undoable; wrap several in
using (Host.Transaction("Label"))to make them one undo step.
Plugin and host
Registration options
UI
Scene
Viewport
Jobs and tasks
Native plugins
Native editor and runtime plugins use the C ABI and the header-only C++ layer: see the C/C++ plugin SDK. For anything the managed API does not wrap, Host.Raw and Host.Context give C# the same C tables (Kroys.Plugins.Native, generated from kroys_plugin.h).
Generated from the XML documentation of Managed/PluginSdk/Api by Tools/BuildDocsSite.py. Every public member is documented (CS1591 is an error in the SDK project).