Skip to content

💰 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 CurrencyBatch to editor scripts.
  • Prevent UnityEditor references 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 via CurrencyResolve.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:

  1. Scene binder (CurrencySetBinder)
  2. First binder found in the scene (includes inactive)
  3. 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);
Batch emission has effect only when the wrapped service stack includes batch event support.

  • 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.
  • BeginBatch does not create a service; it wraps the one you provide.
  • All runtime rules still apply (caps, authority, escrow, idempotency).
  • Always dispose the batch handle (using is recommended).
  • Do not depend on internal decorator classes — they remain hidden by design.
  • The Editor API is intentionally small and stable.

  • DefinitionsCurrencySet, CurrencyDefinition
  • CoreCurrencyBatching, CurrencyResolve, CurrencyFactories
  • Teaching Panels — editor overlays and teachables
  • Persistence — snapshot utilities for editor workflows