💰 Currency – Editor API¶
Assembly: Editor-only asmdef for RevGaming.RevFramework.Currency
The Editor API exposes a minimal, editor-only surface for inspectors, wizards, teachable panels, and diagnostic tools to interact with Currency without touching internal implementation details.
Nothing in this folder is included in runtime builds.
Purpose¶
- Provide a safe gateway for editor tooling to interact with Currency data.
- Avoid exposing internal decorator types or
CurrencyBatchto editor scripts. - Prevent
UnityEditorreferences from leaking into runtime assemblies. - Keep editor tooling aligned with the same resolution and batching semantics as runtime code.
Important
The Editor API does not resolve the active currency service for you.
When tooling needs the composed service, resolve it normally viaCurrencyResolve.ServiceFrom(...).
Key file¶
CurrencyEditorApi.cs¶
This class exposes two editor-friendly helpers.
ResolveSet()¶
Resolves the active CurrencySet using the same logic as runtime convenience code:
- Scene binder (
CurrencySetBinder) - First binder found in the scene (includes inactive)
- Fallback (global, not scene-scoped):
Resources/CurrencySet_Default
public static CurrencySet ResolveSet();
Use this to obtain designer-authored currency definitions inside inspectors, editors, and wizards.
BeginBatch(ICurrencyService svc)¶
Begins a temporary batch scope
(editor-only alias for CurrencyBatching.BeginBatch)
around a provided composed ICurrencyService.
public static CurrencyBatching.CurrencyBatchHandle BeginBatch(ICurrencyService svc);
- Returns a value-type handle that wraps internal batch capture.
- Collapses multiple mutations into one aggregated batch event when supported.
- Ensures subscriptions are cleaned up correctly when disposed.
Note
The batch wraps the exact service instance you pass in.
All composed decorators (Caps, Audit, Authority, RequireEscrow, Idempotency) still apply.
CurrencyBatchHandle¶
public readonly struct CurrencyBatchHandle : IDisposable
{
void Emit(); // Emit batch if armed
void Cancel(); // Cancel batch emission
void Dispose(); // Detach from OnWalletChanged
}
Used by teachable panels, inspectors, and editor windows to perform multi-step editor operations safely.
Usage examples¶
Resolve a designer’s CurrencySet (editor)¶
#if UNITY_EDITOR
var set = CurrencyEditorApi.ResolveSet();
if (set)
Debug.Log($"Loaded {set.All.Count} currencies.");
#endif
Perform an editor batch operation¶
#if UNITY_EDITOR
var svc = CurrencyResolve.ServiceFrom(this); // Resolve composed service normally
using var batch = CurrencyEditorApi.BeginBatch(svc);
// … perform multiple Credit / Debit / SetBalance calls …
batch.Emit();
#endif
The batch prevents repeated UI refreshes and emits one combined batch event when supported by the stack.
Notes & gotchas¶
- Lives in an Editor-only asmdef — excluded from player builds.
BeginBatchdoes not create a service; it wraps the one you provide.- All runtime rules still apply (caps, authority, escrow, idempotency).
- Always dispose the batch handle (
usingis recommended). - Do not depend on internal decorator classes — they remain hidden by design.
- The Editor API is intentionally small and stable.
Related¶
- Definitions —
CurrencySet,CurrencyDefinition - Core —
CurrencyBatching,CurrencyResolve,CurrencyFactories - Teaching Panels — editor overlays and teachables
- Persistence — snapshot utilities for editor workflows