Game.UI.Debug.DebugUISystem
Assembly:
Namespace: Game.UI.Debug
Type: class
Base: UISystemBase
Summary:
DebugUISystem is a UI system that exposes the in-game debug menu to the UI binding layer. It manages the debug menu visibility, the currently selected debug panel, widget bindings for the selected panel, observed debug bindings, and the debug watches. It also coordinates enabling/disabling the underlying DebugSystem and handles user interactions such as showing/hiding the menu, selecting panels, and triggering debug bindings. The class maintains UI ValueBindings and UpdateBindings that the game's UI framework uses to read/update debug UI state.
This class also contains a private nested class Panel which adapts DebugUI.Panel instances for the UI layer. The nested Panel caches the panel's display name, builds widget representations, detects changes (via panel.onSetDirty) and supports JSON writing and disposal of the change subscription.
Fields
-
private const string kGroup = "debug"
Provides a constant group name used when creating ValueBindings / UpdateBindings for the debug UI. -
private ValueBinding<bool> m_EnabledBinding
Binding that reflects whether the debug system is allowed (initial value comes from developer mode configuration). Used to prevent showing the debug UI when the game isn't in developer mode. -
private ValueBinding<bool> m_VisibleBinding
Binding representing whether the debug UI is currently visible. -
private ValueBinding<Panel> m_SelectedPanelBinding
Binding that holds the currently selected Panel wrapper (the nested Panel type). Updated when the selected panel changes. -
private WidgetBindings m_WidgetBindings
Bindings object that exposes the child widgets of the selected panel to the UI. It is updated whenever the selected panel or its children change. -
private ValueBinding<IDebugBinding> m_ObservedBindingBinding
Binding used to expose the currently observed debug binding (for showing details / inspecting a specific binding). -
private EventBinding<IDebugBinding> m_BindingTriggeredBinding
Event binding used to notify the UI layer when a debug binding is triggered via Trigger(IDebugBinding). -
private GetterValueBinding<List<DebugWatchSystem.Watch>> m_WatchesBinding
Getter binding that provides the list of debug watches maintained by DebugWatchSystem. -
private string m_SelectedPanel
Backer for the private selectedPanel property; stores the displayName of the currently selected panel. -
private bool m_ShowDeveloperInfo
Backer for developerInfoVisible; indicates whether developer info should be shown in the UI. -
private static IEnumerable<DebugUI.Panel> visiblePanels
Private static property that returns the list of DebugUI.Panel instances that are not editor-only and that contain at least one non-editor-only widget. Used to build the list of panels that can be selected by the debug UI. -
private static bool debugSystemEnabled
Private static property that returns whether developer mode is enabled in the current GameManager configuration. Used to initialize m_EnabledBinding.
Properties
-
public bool visible => m_VisibleBinding.value
Read-only property exposing whether the debug UI is currently visible. -
[CanBeNull] public IDebugBinding observedBinding { get; set; }
Getter/Setter that proxies to m_ObservedBindingBinding. Used by UI consumers to get or set the currently observed debug binding. -
private string selectedPanel { get; set; }
Private property backed by m_SelectedPanel; stores the displayName of the selected panel. Changing it updates the internal value but selection changes are applied during UpdateSelectedPanel. -
public bool developerInfoVisible { get; set; }
Gets or sets whether developer information should be visible in the debug UI (backed by m_ShowDeveloperInfo).
Constructors
public DebugUISystem()
Default constructor. Marked with [Preserve] attribute in source to avoid code stripping. Initialization of bindings and update bindings happens in OnCreate rather than the constructor.
Methods
protected override void OnCreate()
Initializes all ValueBindings and UpdateBindings for the debug UI group, including:- Enabled/visible flags
- Panels list and selected index bindings
- Selected panel binding
- Widget bindings and default widget bindings
- Observed binding and binding-triggered event
- Watches binding (from DebugWatchSystem)
- Trigger bindings for show/hide/select actions
The method wires the UI bindings into the system so the front-end can control and display the debug UI.
protected override void OnUpdate()
Called every frame; if the debug UI is visible it:- Calls UpdateSelectedPanel() to ensure the selected panel and widgets are synchronized.
- Checks the DebugWatchSystem for changed watches and triggers a watches update when needed.
-
Calls base.OnUpdate() at the end.
-
public void Trigger(IDebugBinding binding)
Triggers the bindingTriggered EventBinding so the UI layer (or other listeners) can respond to an explicit trigger of a debug binding. -
public void Show()
Makes the debug UI visible (if enabled). If this is the first time and the user hasn't dismissed the confirmation, it shows a confirmation dialog warning that achievements will be disabled; if confirmed, the DebugSystem is enabled and achievements are disabled. Otherwise it immediately enables DebugSystem and disables achievements. After enabling, it updates the selected panel. -
public void Hide()
Hides the debug UI and disables the DebugSystem. Also updates the selected panel state. -
private void SelectPanel(int index)
If the debug UI is visible, sets selectedPanel to the displayName of the panel at the given index and updates the selected panel wrapper. -
private void SelectPreviousPanel()
If visible, selects the previous available panel in the list; wraps to the last panel if currently at or before the first. -
private void SelectNextPanel()
If visible, selects the next available panel in the list; wraps to the first panel if currently at or after the last. -
private List<string> GetPanels()
Returns a list of displayName strings for the currently visible panels (uses visiblePanels). -
private void UpdateSelectedPanel()
Synchronizes the m_SelectedPanelBinding (the Panel wrapper) with the currently selected DebugUI.Panel (based on selectedPanel string and visibility). If the selected underlying panel object changes, it disposes the previous wrapper, creates a new Panel wrapper, and updates m_WidgetBindings.children. If the wrapper exists and reports an update (its displayName or children changed), it triggers bindings to update the UI. -
private static int GetPanelCount()
Returns the count of visible panels. -
[CanBeNull] private static DebugUI.Panel GetPanel(int panelIndex)
Returns the DebugUI.Panel at the given index (or null for negative index). Uses visiblePanels with Skip/FirstOrDefault. -
private static int GetPanelIndex(string name)
Finds the index of the panel whose displayName matches the provided name. Returns -1 if not found.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// DebugUISystem sets up bindings for UI; Show/Hide control visibility and DebugSystem state.
}
// Example: Show the debug UI from another system or UI event
var debugUI = World.GetOrCreateSystemManaged<DebugUISystem>();
debugUI.Show();
// Example: Trigger a specific debug binding
debugUI.Trigger(someDebugBinding);
// Example: Observe a debug binding (null to clear)
debugUI.observedBinding = someDebugBindingOrNull;
Notes: - The nested private Panel class adapts DebugUI.Panel for the UI: it caches displayName, rebuilds children widgets via DebugWidgetBuilders.BuildWidgets when the panel marks itself dirty, implements IJsonWritable to serialize displayName, and unsubscribes from panel.onSetDirty when disposed. - The debug UI disables platform achievements when activated to prevent achievement earning while in debug mode. The user may be prompted with a confirmation dialog the first time they open the debug menu unless they've previously dismissed it.