KROYSDOCS
HomeWhat's newv0.1.0
PLUGIN SDK

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#.

NamespaceKroys.Plugins
AssemblyKroysPlugins.Sdk.dll
SDK2.2.0
Types37
START

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

Rules the editor relies on

  • Every callback runs on the editor's main thread, except importers, exporters and the run part of RunTask (worker threads). Log and Post are thread-safe.
  • What a plugin uses is declared in its manifest: capability lines (commands, panels, settings, importers, exporters, asset-types, viewport-tools, tasks, services, automation, components) and permission lines (scene.read, scene.write, assets.write). A call outside them throws KroysException naming 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 calls OnLoad on a new instance. Fields start fresh; GetSetting / SetSetting values stay.
  • Edits of the document scene are undoable; wrap several in using (Host.Transaction("Label")) to make them one undo step.
03

Plugin and host

04

Registration options

05

UI

06

Scene

07

Viewport

08

Jobs and tasks

C ABI

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).