Migrating from SRDebugger
An SROptions class converts to Debug MD one
line at a time. The mapping is mechanical, nothing has to move house,
and you can run both panels side by side while you work through it.
A class in, a call per option out
SRDebugger discovers your cheats: it reflects over a partial class at runtime and infers each widget from the property's type and attributes. Debug MD is told about them: you pass a label, a getter and a setter, and the panel never reflects over anything. Everything that was an attribute becomes a modifier chained onto the same line.
using System.ComponentModel;
using UnityEngine;
public partial class SROptions
{
private float _spawnRate = 1f;
[Category("Combat")]
[DisplayName("Spawn Rate")]
[NumberRange(0, 10)]
[Increment(0.5)]
public float SpawnRate
{
get { return _spawnRate; }
set { _spawnRate = value; OnPropertyChanged("SpawnRate"); }
}
}
DMD.Options.AddFloat("Spawn Rate", () => _spawnRate, v => _spawnRate = v)
.WithRange(0f, 10f)
.WithStep(0.5f)
.InCategory("Combat");
Three consequences worth knowing before you start:
- The label is data, not an identifier. It is the
first argument, so spaces, punctuation and renames cost nothing - and
[DisplayName]has no reason to exist. - Your state stays where it is. The getter and
setter can point at a field, a property, a static, or straight at
Time.timeScale. Debug MD never owns the value. OnPropertyChangedgoes away. Visible widgets re-read your getter several times a second, so values changed by gameplay update on screen by themselves.
Where are the attributes?
There aren't any, on purpose. Debug MD has no
[DebugOption], no discovery pass and no reflection: the
registration call is the whole mechanism. That is worth a paragraph
rather than a shrug, because it is the first thing an SRDebugger user
looks for.
Attributes earn their place when the alternative is verbose. In SRDebugger the alternative is a partial class, a backing field, a property and a change notification, so a one-line attribute is a real saving. Debug MD's registration is already one line - and it is shorter than the attribute form it would replace:
// What an attribute would have looked like, if we had one.
[DebugOption(Category = "Cheats")]
public static bool GodMode { get; set; }
// What you write instead. One line, and _god can be anything.
DMD.Options.AddToggle("God Mode", () => _god, v => _god = v)
.InCategory("Cheats");
The registration also reaches further. An attribute can only decorate
a member it owns and can mutate - which in practice means a static or a
property on a discoverable singleton. A getter and setter pair can point
at a private field, a local, a computed expression, or
Time.timeScale and other properties on objects you did not
write. Nothing has to be restructured to become debuggable.
And it keeps a promise that matters on device: with no attribute scan there is nothing for IL2CPP's managed stripping to remove behind your back. Options bind through the delegates you passed, so Managed Stripping Level = High is simply a setting, not a thing to test around.
Converting one option
- Take the label. Use the
[DisplayName]string if there is one, otherwise the property name - spelled the way you want to read it in the panel. - Pick the call from the type.
AddToggle,AddInt,AddFloat,AddText,AddChoice,AddButton- see the member table. - Hand it the getter and setter. Two lambdas over
the field the property already wraps. Drop the
OnPropertyChangedcall; keep any side effects (they live in the setter lambda now). - Chain the attributes. Numeric modifiers first,
then placement:
.WithRange(...).WithStep(...).InCategory(...). The attribute table is the full list.
Attributes
| SRDebugger | Debug MD | Notes |
|---|---|---|
[DisplayName("Spawn Rate")] |
First argument | The label is always explicit, so there is nothing to override. |
[Category("Combat")] |
.InCategory("Combat") |
Uncategorized options land in General. Debug MD
adds a level above: .InTab("Economy") -
see Tabs, rows & layout. |
[NumberRange(0, 10)] |
.WithRange(0f, 10f) |
Clamps the value and adds a range bar under it that drags like a slider. |
[Increment(0.5)] |
.WithStep(0.5f) |
Steps the arrows either side of the value and snaps the range
bar. An int step is at
least 1; a float step of 0 is
continuous. |
[Sort(10)] |
.WithOrder(10) |
Lower values first, within the category. |
Keep the numeric modifiers ahead of the placement ones -
WithRange and WithStep exist on the typed
option, and InTab, InCategory,
WithOrder, WithIcon return the base type.
Members
In SROptions | Becomes |
|---|---|
bool property | AddToggle(name, get, set) |
int property | AddInt(name, get, set) |
float property | AddFloat(name, get, set) |
string property | AddText(name, get, set) |
| enum property | AddChoice(name, get, set) - opens the searchable list rather than a dropdown |
byte, sbyte, short, ushort | AddInt; the getter widens by itself, the setter casts back: v => _lives = (byte)v |
double property | AddDouble(name, get, set) - full precision, no cast needed |
uint property | AddLong; the getter widens by itself, the setter casts back: v => _id = (uint)v. Its top half does not fit an int. |
long property | AddLong - the full 64-bit range, no cast needed |
| Read-only property (no setter) | The same call with the setter omitted - every value option renders read-only. AddInfo(name, get) is the shorthand for a string readout. |
public void method, no parameters | AddButton(name, Method) - pass the method group; it needs no signature change. Add .WithKeyBinding(KeyCode.R) for a desktop hotkey. |
| A property backed by a big collection | AddPicker - a virtualized, searchable list with icons. This is what the enum-with-40-members workaround becomes; see Pickers. |
A worked example
A representative cheat class, converted whole. Registration moves
from a partial class Unity discovers on its own into one place you
control - a bootstrap object, or a
RuntimeInitializeOnLoadMethod:
using System.ComponentModel;
using UnityEngine;
public partial class SROptions
{
private bool _godMode;
private byte _lives = 3;
[Category("Player")]
[Sort(0)]
public bool GodMode
{
get { return _godMode; }
set { _godMode = value; OnPropertyChanged("GodMode"); }
}
[Category("Player")]
[NumberRange(0, 9)]
public byte Lives
{
get { return _lives; }
set { _lives = value; OnPropertyChanged("Lives"); }
}
[Category("Player")]
[DisplayName("Kill Player")]
public void KillPlayer()
{
Game.Player.Kill();
}
[Category("Net")]
public int Ping
{
get { return Net.PingMs; }
}
}
using UnityEngine;
public class DebugCheats : MonoBehaviour
{
private bool _godMode;
private byte _lives = 3;
private void Start()
{
DMD.Options.AddToggle("God Mode", () => _godMode, v => _godMode = v)
.InCategory("Player").WithOrder(0);
DMD.Options.AddInt("Lives", () => _lives, v => _lives = (byte)v)
.WithRange(0, 9)
.InCategory("Player");
DMD.Options.AddButton("Kill Player", () => Game.Player.Kill())
.InCategory("Player");
DMD.Options.AddInt("Ping", () => Net.PingMs) // no setter → read-only
.InCategory("Net");
}
}
Registration runs once per play session and the registry starts each
session empty, so Start on a bootstrap object is the natural
home. If the object registering the options can be destroyed mid-session,
bind the options to an owner or a scope and cleanup takes care of
itself - Lifetime & scopes.
The rest of the API
| SRDebugger | Debug MD |
|---|---|
SRDebug.Instance.ShowDebugPanel() | DMD.ShowPanel() |
HideDebugPanel() | DMD.HidePanel() |
IsDebugPanelVisible | DMD.IsPanelVisible |
PanelVisibilityChanged | DMD.PanelVisibilityChanged - same use: mute game input while the panel is up |
DestroyDebugPanel() | DMD.DestroyPanel(), or the Destroy On Close setting |
SRDebug.Init() | Nothing to call - Auto Load creates the panel on startup. To keep starting it from your own code, turn Auto Load off and call DMD.Init() in the same place. |
OptionDefinition.Create(name, getter, setter, category, sort) | Option.Toggle/Int/Float/Text/Choice(...) then DMD.Options.Add(option) - or the Add* shorthands |
AddOption / RemoveOption | DMD.Options.Add(...) returns an OptionHandle; handle.Remove() takes it away |
AddOptionContainer(object), DynamicOptionContainer | DMD.Options.CreateScope() for a batch that dies together, or Add(option, owner) to tie options to a Unity object. Cleanup is automatic in both cases. |
PinOption(name) / UnpinOption(name) | handle.Pin() / handle.Unpin() - by handle rather than by name, so nothing breaks on a rename. See Pin to screen. |
PinAllOptions(category), ClearPinnedOptions() | Pin the handles you kept, or pin from the panel - pins made on a device persist there across launches. |
AddSystemInfo(entry, category) | DMD.Options.AddInfo(name, getter), in a tab or category of your own |
DISABLE_SRDEBUGGER, SRDebugEditor.SetEnabled(false) | Nothing to set: release builds leave Debug MD out unless they define DEBUGMD_ENABLED - see Stripping from builds |
#if !DISABLE_SRDEBUGGER around your calls | Not needed. Every DMD call compiles and no-ops in a stripped build. |
| Trigger, entry code, layout settings | One settings asset - Window › Debug MD › Settings, plus per-device overrides from the panel itself |
Finishing the move
Once every option is registered and verified on device:
- Delete the
OnPropertyChangedcalls and theSROptionspartial files. Game code that readSROptions.Current.Xnow reads your own field - the debug panel is no longer the owner of the value. - Remove
DISABLE_SRDEBUGGERfrom your release build configuration - release builds leave Debug MD out by themselves - and remove the#ifguards that wrapped debug calls. A non-development build that should keep the panel definesDEBUGMD_ENABLED. - Remove the SRDebugger folder, then run a stripped build and check the build report - see What ships, what doesn't.
Two SRDebugger features have no counterpart here today: the bug
reporter, and world-space panel mode for VR. The system-info tab is
replaced by read-only AddInfo rows you place yourself, and
the docked mini console by the
error signal and a
pinnable profiler.
SRDebugger is a product of Stompy Robot Ltd. Debug MD is an independent tool, not affiliated with or endorsed by Stompy Robot; the names are used here only to describe the migration.