Defining a bridge in C#
A bridge is a partial C# class marked with [Bridge] and inherited from LoomBridgeBase:
using Loom;
[Bridge]
public partial class UIBridge : LoomBridgeBase
{
public string CurrentScreen { get; set; } = "MainMenu";
[BridgeAction]
public void StartGame()
{
CurrentScreen = "Hud";
}
} Loom discovers bridge members like this:
- Public properties are state (by convention).
- Public
Event<T>properties are events (by convention). - Methods are actions only when tagged
[BridgeAction]. A plainpublicmethod stays internal. The tag also works on a method of a nested state DTO, which surfaces at its dotted path (bridge.boot.setProgress(v)).
Partial class
The bridge class must be partial because Loom generates companion code at
compile time.
[Bridge]
public partial class UIBridge : LoomBridgeBase
{
} One root bridge
Most games should have one root bridge for the UI surface. You can organize larger contracts with nested DTOs and state objects rather than separate bridge roots.
Ignore a member
Use [BridgeIgnore] for public members that should stay off the bridge:
[BridgeIgnore]
public string InternalDebugName { get; set; } = ""; Rename a member
Use [BridgeName] if the UI-facing name must differ from the C# name:
[BridgeName("hp")]
public int Health { get; set; } Prefer normal names unless you are preserving a public UI contract.
Regenerate types
After changing bridge members, run:
Loom -> Regenerate Types Then restart the dev server if it was already running.