C# SDK
File: sdk/csharp/ShireSdk.cs (namespace Shire.Sdk, .NET 8+, no external
packages).
The client opens one duplex NamedPipeClientStream, runs a reader loop and
resolves requests by id. .NET uses asynchronous/overlapped pipe I/O, so the
reader does not deadlock the writer.
Connect
using Shire.Sdk;
using var plugin = await Client.ConnectAsync();
It reads SHIRE_PLUGIN_PIPE, SHIRE_PLUGIN_TOKEN and SHIRE_PLUGIN_ID,
connects, starts the reader and performs the handshake.
Calls
await plugin.LogAsync("hello");
await plugin.NotifyAsync("Title", "Body");
var position = await plugin.PlayerPositionAsync();
var scene = await plugin.SceneAsync();
var entities = await plugin.EntitiesAsync(64);
var markers = await plugin.MarkersAsync(128);
await plugin.TeleportAsync(1, 2, 3, 0);
await plugin.StorageSetAsync("key", new { n = 1 });
var value = await plugin.StorageGetAsync("key");
await plugin.SubscribeAsync("player.position", "scene.changed");
Errors throw ShireException with Code/Data.
UI
var layout = "[" +
Client.Text("Hello from C#", "title") + "," +
Client.Button("ping", "Ping") + "," +
Client.Toggle("enabled", "Enabled", true) + "," +
Client.Slider("speed", "Speed", 5, 0, 10) + "]";
await plugin.SetUiJsonAsync(layout);
await plugin.UpdateUiAsync("speed", new { value = 7.0 });
Client.Text/Section/Button/Toggle/Slider/Progress return JSON descriptor
strings. SetUiJsonAsync sends the array; UpdateUiAsync merges the supplied
object with the component id.
Events
plugin.OnEvent("player.position", data =>
Console.WriteLine($"{data.GetProperty("x")} {data.GetProperty("z")}"));
plugin.OnUiEvent((component, type, value) =>
_ = plugin.NotifyAsync("UI", $"{component}: {value}"));
plugin.Run(); // blocks; the reader task keeps running
Build and manifest
dotnet publish -c Release -o publish
The generated project targets net8.0 and outputs publish/Plugin.dll. The
manifest:
{
"language": "dotnet",
"entrypoint": "publish/Plugin.dll",
"permissions": ["notifications.show", "ui.create"]
}
The Host launches dotnet publish/Plugin.dll. shire-plugin build detects the
.csproj and runs dotnet publish -c Release -o publish.