Unity Debug Sheet
repository·master·Indexed 20 days ago
https://github.com/haruma-k/unitydebugsheetA hierarchical debug menu system for Unity (version 1.5.4) that provides an intuitive, touch-friendly GUI for managing debug commands. It allows developers to create organized debug interfaces with buttons, switches, sliders, and labels, making it particularly useful for mobile development. The system supports custom cells, async lifecycle methods, and integrations with Unity system information, In-game Debug Console, and Graphy.
What's inside Unity Debug Sheet
- Unity Debug Sheet is a hierarchical debug menu system for Unity designed to create intuitive, organized, and easily navigable debug interfaces. It is particularly well-suited for mobile platforms due to its touch-friendly GUI and supports both standard and vertical layouts. It allows developers to quickly add debug commands like buttons, switches, and sliders to manage game state during development.
Handle multiple scenes with DebugSheet
masterBy default,
DebugSheetCanvasacts as a singleton. If multipleDebugSheetCanvasobjects exist in different scenes, the first one instantiated is used, and subsequent ones are destroyed.To safely handle initialization across multiple scenes where loading order might be unpredictable, use
DebugSheet.GetOrCreateInitialPage(). This method retrieves an existing initialized page if available, or initializes a new one if not.If you need multiple independent debug sheets, uncheck the Singleton option on the
DebugSheetcomponent.Manage DebugSheet singleton in multiple scenes
masterBy default,
DebugSheetCanvasacts as a singleton. If multipleDebugSheetCanvasobjects exist in different scenes, the first one instantiated is used, and subsequent ones are destroyed.To handle unpredictable scene loading orders, use
DebugSheet.GetOrCreateInitializePage()to retrieve and initialize an existing page if one is already active.If you want to disable singleton behavior, uncheck the Singleton option on the
DebugSheetcomponent.Create a custom cell
masterTo implement a custom cell, you must create two components: a
Cell<TModel>component for the UI and aCellModelclass for the data.Implementation Steps:
- Define the Model: Create a class inheriting from
CellModelcontaining the data properties. - Define the Cell: Create a class inheriting from
Cell<CustomCellModel>. Implement theSetModel(model)method to apply model data to your UI elements. - UI Setup: Create a Prefab with your UI.
- Crucial: Attach a
Layout Elementto the root GameObject and set aPreferred Height. - Crucial: Set a fixed width for the cell.
- Crucial: Attach a
- Registration: Add your new cell prefab to the Cell Prefabs list in the
Debug Sheetconfiguration. - Usage: Call your custom
Add[CellName]method from your debug page.
using UnityDebugSheet.Runtime.Core.Scripts; using UnityEngine; using UnityEngine.UI; public sealed class CustomTextCell : Cell<CustomTextCellModel> { [SerializeField] private Text _text; [SerializeField] private LayoutElement _layoutElement; private const int Padding = 36; protected override void SetModel(CustomTextCellModel model) { _text.text = model.Text; _text.color = model.Color; _layoutElement.preferredHeight = _text.preferredHeight + Padding; } } public sealed class CustomTextCellModel : CellModel { public string Text { get; set; } public Color Color { get; set; } = Color.black; }- Define the Model: Create a class inheriting from
Open and close the debug menu
masterThe debug menu can be accessed via several methods:
- Flick Gesture: Flick up or down along the edge of the screen. The flickable area is approximately 6mm from the screen edge. This behavior can be configured on the Debug Sheet component via Flick To Open (enabling/disabling sides or disabling entirely).
- Click Gesture: Configure the Click To Open area and Click Count To Open on the Debug Sheet component to open the menu via taps.
- Keyboard Shortcut: The default shortcut is Control (Command on Mac) + Shift + D. This can be customized in the Keyboard Shortcut field of the Debug Sheet component.
- Scripting: You can programmatically toggle the menu by accessing the
StatefulDrawerControlleron theDebugSheetCanvas > Drawerobject.
// Programmatic toggle via script // These scripts are attached on the GameObject "DebugSheetCanvas > Drawer". StatefulDrawer drawer; StatefulDrawerController drawerController; // Toggle debug sheet. var isClosed = Mathf.Approximately(drawer.Progress, drawer.MinProgress); var targetState = isClosed ? DrawerState.Max : DrawerState.Min; drawerController.SetStateWithAnimation(targetState);Add a link to a debug page
masterTo navigate to a custom debug page, you can add a link button to the root page. Use
DebugSheet.Instance.GetOrCreateInitialPage()to access the root, then callAddPageLinkButton<T>()whereTis your page class.Note: If you want your custom page to be the actual starting page (instead of just a link on the root page), use
Initialize<T>()instead of adding a link button.using UnityDebugSheet.Runtime.Core.Scripts; using UnityEngine; public sealed class DebugSheetController : MonoBehaviour { private void Start() { // Get or create the root page. var rootPage = DebugSheet.Instance.GetOrCreateInitialPage(); // Add a link transition to the ExampleDebugPage. rootPage.AddPageLinkButton<ExampleDebugPage>(nameof(ExampleDebugPage)); } }Exclude Unity Debug Sheet from release builds
masterTo ensure debug tools are not included in production builds, follow these steps:
Code Exclusion: Add the
EXCLUDE_UNITY_DEBUG_SHEETsymbol to your Scripting Define Symbols. Wrap all code that accesses Unity Debug Sheet in preprocessor directives:#if !EXCLUDE_UNITY_DEBUG_SHEET // Debug sheet related code #endifAlternatively, place debug code in a separate assembly (
.asmdef) and use Define Constraints.Resource Exclusion: Delete any Resources folders containing debug menu assets.
Scene Cleanup: Remove the
Unity Debug SheetGameObject from your production scenes.
Create custom cells
masterTo implement a custom cell, you must create two parts: a component inheriting from
Cell<TModel>and a model inheriting fromCellModel.Implementation Steps:
- Define the Model: Create a class inheriting from
CellModelto hold the data. - Define the Cell: Create a component inheriting from
Cell<CustomModel>. OverrideSetModel(model)to apply the model data to your UI elements. - Setup Prefab:
- Attach a Layout Element to the root GameObject and set a Preferred Height.
- Set the width to a fixed value.
- Create a prefab from this GameObject.
- Register: Add the new prefab to the Cell Prefabs list on the
DebugSheetcomponent.
Example Implementation:
using UnityDebugSheet.Runtime.Core.Scripts; using UnityEngine; using UnityEngine.UI; public sealed class CustomTextCell : Cell<CustomTextCellModel> { [SerializeField] private Text _text; [SerializeField] private LayoutElement _layoutElement; private const int Padding = 36; protected override void SetModel(CustomTextCellModel model) { _text.text = model.Text; _text.color = model.Color; _layoutElement.preferredHeight = _text.preferredHeight + Padding; } } public sealed class CustomTextCellModel : CellModel { public string Text { get; set; } public Color Color { get; set; } = Color.black; }- Define the Model: Create a class inheriting from
Display Unity System Information
masterYou can add debug pages to display information from various Unity classes using the
UnityDebugSheet.Unityextension.Available Debug Pages
Class name of DebugPage Description SystemInfoDebugPageShow the information of SystemInfoclass.ApplicationDebugPageShow the information of Applicationclass.TimeDebugPageShow the information of Timeclass.QualitySettingsDebugPageShow the information of QualitySettingsclass.ScreenDebugPageShow the information of Screenclass.InputDebugPageShow the information of Inputclass.GraphicsDebugPageShow the information of Graphicsclass.PhysicsDebugPageShow the information of Physicsclass.Physics2DDebugPageShow the information of Physics2Dclass.Setup Steps
- Assembly Reference: If you are using your own assembly, add
UnityDebugSheet.Unityto your referenced assemblies. - Implementation: Use
DefaultDebugPageBase.AddPageLinkButton<T>to add the page to your debug menu.
DefaultDebugPageBase.AddPageLinkButton<SystemInfoDebugPage>("System Info");- Assembly Reference: If you are using your own assembly, add
Integrate Graphy extension
masterYou can add a debug menu link to control Graphy using the Unity Debug Sheet extension.
Setup
- Install and set up Graphy.
- If NOT installed via Package Manager: Add
UDS_GRAPHY_SUPPORTto your Scripting Define Symbols and restart Unity. - If using a custom assembly, add
UnityDebugSheet.Graphy(Assets/UnityDebugSheet/Runtime/Extensions/Graphy/UnityDebugSheet.Graphy.asmdef) to your assembly references. - Add the link button in your debug page code.
DefaultDebugPageBase.AddPageLinkButton<GraphyDebugPage>( "Graphy", onLoad: x => x.page.Setup(GraphyManager.Instance) );Integrate In-game Debug Console
masterThis extension links Unity Debug Sheet with the In-game Debug Console OSS to allow accessing the console via the debug menu.
Setup Steps
- Install and setup In-game Debug Console.
- Scripting Define Symbols: If you did not install via the Package Manager, add
UDS_INGAMEDEBUGCOSOLE_SUPPORTto your Scripting Define Symbols and restart Unity. - Assembly Reference: If using your own assembly, add
UnityDebugSheet.IngameDebugConsoleto your referenced assemblies. - Implementation: Use the
onLoadcallback to pass theDebugLogManager.Instanceto the page setup.
DefaultDebugPageBase.AddPageLinkButton<IngameDebugConsoleDebugPage>("In-Game Debug Console", onLoad: x => x.page.Setup(DebugLogManager.Instance));Integrate Graphy
masterThis extension links Unity Debug Sheet with Graphy to display FPS, Memory, and other metrics within your debug menu.
Setup Steps
- Install and setup Graphy.
- Scripting Define Symbols: If you did not install via the Package Manager, add
UDS_GRAPHY_SUPPORTto your Scripting Define Symbols and restart Unity. - Assembly Reference: If using your own assembly, add
UnityDebugSheet.Graphyto your referenced assemblies. - Implementation: Use the
onLoadcallback to pass theGraphyManager.Instanceto the page setup.
DefaultDebugPageBase.AddPageLinkButton<GraphyDebugPage>("Graphy", onLoad: x => x.page.Setup(GraphyManager.Instance));