Varp Debug Menu by hww - 7

Games & Projects

Simple debug menu for Unity

Unknown VersionMIT LicenseUpdated 1 year agoCreated on February 12th, 2019
Go to source

Debug Menu

It is easy to use, lightweight library initially forked from wataru-ito/DebugMenu but deeply modifyed.

The library renders as text, in game menu.

// The fields to modify by menu
public enum TrafficLight { Red,Green, Blue }
public TrafficLight enumValue;
public bool toggleValue;
public int integerValue;
public float floatValue;
// Create new menu
new DebugMenu("Edit/Preferences");
new DebugMenuToggle("Edit/Preferences/Toggle", () => toggleValue, value => toggleValue = value, 1);
new DebugMenuInteger("Edit/Preferences/Integer", () => integerValue, value => integerValue = value, 2);
new DebugMenuFloat("Edit/Preferences/Float", () => floatValue, value => floatValue = value, 3);
new DebugMenuAction("Edit/Preferences/Action", (item,tag) => { Debug.Log("Action"); }, 4);
new DebugMenuEnum<TrafficLight>("Edit/Preferences/TraficLight", () => enumValue, value => enumValue = value, 5);
new DebugMenu("Edit/Preferences/Extra Preferences", 10);

Picture1 Picture2 Picture3

Other way is to add items directly to menu.

var menu, new DebugMenu("Edit/Preferences");
new DebugMenuToggle(menu, "Toggle", () => toggleValue, value => toggleValue = value, 1);
new DebugMenuInteger( menu, "Integer",() => integerValue, value => integerValue = value, 2);
new DebugMenuFloat(menu, "Float", () => floatValue, value => floatValue = value, 3);
new DebugMenuAction(menu, "Action", (item,tag) => { Debug.Log("Action"); }, 4);
new DebugMenuEnum<TrafficLight>(menu, "TraficLight", () => enumValue, value => enumValue = value, 5);

Default Value

For integer, floats and enum types creating new DebugMenuItem will capture current value as defaut. When value is default it displayed as bright green color. Information about other color tags see below.

  • booleans
    • yellow color of label for enabed feture
    • white color of label for disabled feature
  • integers, floats, enums
    • bright green color of value for default
    • yellow color of value and label for not default value
  • actions
    • gray color for inactive action
    • other color for active action

Keyboard Shortcuts

  • E show or hide menu without closing it
  • ESC close current menu and display previous, or hide menu if there are no more
  • W,S move previous and next menu item
  • A,D edit menu item, open close submenu
  • R reset value to default
  • Shift-A,Shift-D edit menu item even if menu is closed
  • Shift-R reset value to default even if menu is closed


Menu manager sends messages to menu items for rendering and modifying items .

public enum EvenTag
    Null,               //< Nothing 
    Render,             //< Render item, update label, value and colors
    Left,               //< Decrease value or call action
    Right,              //< Increase value or call action
    Up,                 //< Go to previous item 
    Down,               //< Go to next item
    Reset,              //< Reset value to default
    OpenMenu,           //< When menu open    
    CloseMenu           //< When menu closed


The action code can update the item’s fields, and differently response for events: Inc,Dec and Reset

new DebugMenuAction("Edit/Preferences/Action", (item,tag) => { 
        switch (tag)
        case EventTag.Right:
           item.value = "Increment";
        case EventTag.Left:
           item.value = "Decrement";
}, 1);

Open and Close Menu Events

Possible to add menu items when menu opens, and remove items when it closes.

new DebugMenu("Edit/Preferences/Extra Preferences", 30)
    .OnOpen(menu => 
        new DebugMenuToggle("Toggle2", menu, () => toggleValue, value => toggleValue = value);
    .OnClose(menu =>

Refresh and AutoRefresh Menu

If values in menu can be modified by game, to display it the menu should be rendered time to time.

new DebugMenu("Edit/Preferences").AutoRefresh(1f);

Set value 0 will never refresh menu. Alternative way is calling RequestRefresh method.


Increment Step and Precision

For integers and floats: The step field is a step for Inc and Dec evens. The format field is argument for ToString(…) method.

For floats The precision field is number of digits after period. For example increment=5 and precision=2 will make increment step 0.05

Other Syntax Sugar

// For DebugMenu class
DebugMenu OnOpen(Action<DebugMenu> onOpen)
DebugMenu OnClose(Action<DebugMenu> onClose)
DebugMenu AutoRefresh(float period)

// For MenuItem class
DebugMenuItem Order(int order)
DebugMenuItem AddToMenu(DebugMenu menu)
DebugMenuItem Value(string value)
DebugMenuItem LabelColor(string value)
DebugMenuItem ValueColor(string value)

// For DebugMenuEnum class
DebugMenuEnum<T> Default(T value)

// For DebugMenuInteger class
DebugMenuInteger Default(int value)
DebugMenuInteger Step(int value)
DebugMenuInteger Format(string value)

// For DebugMenuFloat class
DebugMenuFloat Default(float value)
DebugMenuFloat Precision(int value)
DebugMenuFloat Step(int value)
DebugMenuFloat Format(string value)
Show all projects by hww