Custom delivery
A delivery mode decides how baked databases reach the running game. The settings asset chooses the mode, and a plugin can add one, such as a project's own bundle system.
The two halves of a mode
A mode is two halves joined by one id.
| Half | Contract | What it does |
|---|---|---|
| Editor | IDatabaseDeliveryStrategy | Decides where the bake writes and how the assets are published |
| Runtime | IDatabaseLoader | Turns the key "SheetForge/{tab}" into a loaded asset |
The three built-in modes are written against exactly these contracts. Their ids are addressables, resources and direct, the constants in SheetForgeDeliveryIds.
Write the editor half
Implement IDatabaseDeliveryStrategy from SheetForge.Editor.Delivery. Put it in an Editor assembly that references SheetForge.Editor. SheetForge.Editor is not auto-referenced, so name it in your asmdef.
How the strategy is discovered
DeliveryStrategyRegistry discovers the strategy through TypeCache, exactly like a source provider. A public parameterless constructor is the whole requirement. The mode then appears in the settings dropdown after the built-ins, sorted by id.
- Ids are trimmed and lower-cased before comparison.
- An empty
Idopts out of discovery. - A duplicate id is refused with a warning, and the first stands.
- An assembly that the plugin compatibility gate refuses is not offered here either.
Strategy members
| Member | Asked when | Answer |
|---|---|---|
string Id | Discovery | The stable id, also stored in assetDeliveryId |
string DisplayNameKey | The settings dropdown | A localization key, or a plain sentence. An unregistered key is shown as written |
IReadOnlyCollection<string> AllowedGatedTypes | Import, reflect pre-flight, Problems | Which gated asset cell types a column may use in this mode |
bool EnsureAvailableOrGuide() | Every pipeline entry | true to proceed, false to stop the run |
bool RequiresPackage(out string packageId) | The Getting Started status row, the SheetForge Setup notice | Whether a Unity package must be present, and which |
bool ValidateBakeOutputFolder(string folder, out string reasonKey, out string suggestedFolder) | The settings inspector, a mode change | Whether the bake folder is somewhere this mode can deliver from |
string AssetPathOf(string outputFolder, string tabName) | Every asset a bake writes | The project-relative path of one tab's baked database |
void AfterBake(IReadOnlyList<BakedDatabaseInfo> baked, string bakeOutputFolder, ErrorCollector errors, IReadOnlyList<string> preservedTabs) | Once, after every asset is written | Publish the baked assets |
IReadOnlyCollection<string> DeliveredKeys() | The Health Check, the pre-build freshness gate | The keys this mode can deliver right now |
Gated cell types
The gated asset cell types are AssetRef and ResourceRef. AllowedGatedTypes names which of them a column may use in this mode. A gated type outside the set is AssetCellTypeNotAllowedInDeliveryMode.
DirectRef and custom types are never gated.
Availability check
EnsureAvailableOrGuide() is asked at every pipeline entry: import, Export, Push and reflect.
Return true to proceed. Return false after showing your own guidance. The run then stops with nothing partial.
Bake folder and asset paths
When ValidateBakeOutputFolder refuses a folder, it returns the reason's localization key and a folder that would work. The settings Inspector offers that folder as one button.
AssetPathOf decides the layout. The layout belongs to the mode, because the mode is what has to find the asset again.
Publish after the bake
AfterBake publishes. It can register addresses, write a catalogue or upload. Failures go into errors, never thrown. preservedTabs are tabs absent from this bake that must not be cleaned up.
BakedDatabaseInfo hands AfterBake each database as TabName, AssetPath, Table, Database and Key.
| Value | Holds |
|---|---|
Table | The parsed sheet. May be null |
Database | The loaded asset. Null when it could not be read back |
Delivered keys
DeliveredKeys() serves the Health Check and the pre-build freshness gate. The question "will the game find its data" is answered by the mode that would have to find it.
Write the runtime half
Implement IDatabaseLoader from SheetForge.Runtime. A runtime assembly needs to reference nothing but SheetForge.Runtime.
Loader members
The loader has three members.
| Member | Rule |
|---|---|
SheetForgeLoadHandle<TDatabase> Load<TDatabase>(string key) | Always return a handle. Return a finished failed one when the request is hopeless |
bool SupportsSynchronousCompletion | Answer truthfully, because WaitForCompletion() trusts it |
void Release(object loaded) | A no-op when your system does not reference count |
Build the handle with new SheetForgeLoadHandle<T>(completeSynchronously, release). Finish it with SetResult or SetError. You can also return FromResult or FromError outright.
Register the loader
Register the loader before the first load.
using UnityEngine;
using UnityEngine.Scripting;
using SheetForge.Runtime;
[Preserve]
static class MyBundleDelivery
{
[Preserve]
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Register() => SheetForgeDatabases.RegisterLoader("mybundles", new MyBundleLoader());
}Registering an id twice replaces the earlier loader. This is how a plugin overrides a built-in mode on purpose.
How the game learns the mode
Game code never states the mode. The game learns it from a registration that the import generates.
The generated registration file
Every import emits one small file into the generated-code folder, {Settings}_{guid8}DeliveryRegistration.cs.
- The class is named after the settings asset plus the first eight characters of its GUID. Two settings assets that share a file name never overwrite each other's registration.
- The class is marked
[Preserve]. - Its one method runs at
SubsystemRegistration.
That method calls SheetForgeDatabases.Register("<id>", new string[] { "Tab1", "Tab2", … }) with the tabs of its own workbook.
A load looks its tab up in that table, and the loader registered under that tab's delivery id answers. This is what lets two workbooks in one project deliver differently.
Registration rules
- Registration is idempotent. The hook running again costs nothing.
- A tab claimed for a second, different mode keeps the first and logs one warning. The same tab name in two workbooks is a clash the import already reports.
- The id also enters the schema fingerprint, so changing the mode regenerates the code and re-bakes.
The default mode
SheetForgeDatabases.Configure("<id>") exists for a plugin or a hand-written bootstrap. It states the default mode, the one that loads a tab no registration named.
- The first caller wins. A second, different id logs a warning.
- With no default stated, such a tab falls back to Addressables.
DeliveryIdFor(tab) reads the table back. Null means "registered by nobody". A failed load of such a tab says the same thing first.
Cells are not the mode's business
A custom mode does not need to handle cells. A plugin that wants its own asset reference notation registers an ordinary custom cell type. That is ICellValueParser, or ICellWrapperType for a MyRef<T> shape. Codegen, baking and Export already cover it through those contracts.
The one link between the two is AllowedGatedTypes, and only for the two built-in gated names.
Current state
Both halves are public. A test assembly in the product's own tests, one with no InternalsVisibleTo, implements them from outside as a probe. The strategy is found by discovery, and the loader answers a real LoadAsync.
No shipped third-party mode exists yet. The three built-ins are the only implementations that exist.
Next steps
- Choose a delivery mode
Compare the three built-in modes.
- Pipeline and sources
Add an import source, which is discovered the same way.
- Editor assembly
The types of the delivery seam.
- Runtime assembly
The loader, the load handle and the database registry.