Skip to content

Game.Debug.AudioDebugUI

Assembly:
Namespace: Game.Debug

Type: static class

Base: System.Object

Summary: Provides an in-game debug UI for audio systems (primarily the radio subsystem). This static debug container builds a DebugUI tab named "Audio" that exposes radio and audio clip diagnostics — current station/program, currently playing clip, per-source progress/remaining time, next automatic check time, a Reload button, and aggregate statistics for loaded and playing audio clips. The class relies on AudioManager, AudioManager.instance.radio (Radio), FormatUtils, Time, and the game's DebugUI framework (DebugContainer, DebugTab, DebugUI.* widgets, ObservableList). The BuildAudioDebugUI method is marked for discovery by the debug system via attributes.


Fields

  • None
    This static debug container holds no instance or static fields; it builds its widgets on demand inside BuildAudioDebugUI().

Properties

  • None
    There are no properties on this static debug helper.

Constructors

  • None (static utility class)
    AudioDebugUI is a static class and has no public constructors. It is intended to be discovered and used by the debug reflection system via its attributes.

Methods

  • private static System.Collections.Generic.List<DebugUI.Widget> BuildAudioDebugUI()
  • Attributes: [DebugTab("Audio", -4)] — this marks the method as a debug tab titled "Audio" with priority -4. The class itself is marked with [DebugContainer] to be discovered by the debug system.
  • Summary: Constructs and returns a list of DebugUI.Widget instances grouped into two containers: "Radio" and "Clips".
  • Behavior/detail:
    • Reads the active Radio instance from AudioManager.instance.radio and builds a set of DebugUI.Value widgets that display:
    • Current radio station (radio?.currentChannel?.name)
    • Current program (radio?.currentChannel?.currentProgram?.name)
    • Currently playing clip name (radio?.currentlyPlayingClipName ?? "")
    • Source0 progress: shows an "x " prefix if source 0 is the active source, then elapsed/duration formatted with FormatUtils.FormatTimeMs
    • Source0 remaining: shows "x " if active and remaining time via radio?.GetAudioSourceTimeRemaining(0)
    • Source1 progress: analogous for source 1
    • Source1 remaining: analogous for source 1
    • Next check: radio?.nextTimeCheck - Time.timeSinceLevelLoad (time until next radio scheduling check)
    • Adds a DebugUI.Button labeled "Reload" that calls radio?.Reload()
    • Adds a "Clips" container with two DebugUI.Value widgets:
    • Loaded clips: uses a local helper GetLoadedClips() which calls AudioManager.AudioSourcePool.Stats(out loadedSize, out maxLoadedSize, out loadedCount, out , out ) and formats sizes using FormatUtils.FormatBytes, returning "X / Y (count)".
    • Playing clips: uses GetPlayingClips() which calls AudioManager.AudioSourcePool.Stats(out , out , out _, out playingSize, out playingCount) and returns "size (count)".
  • Notes:
    • The method uses null-conditional operators and guards (radio? ...) to avoid null-reference exceptions if the audio manager or radio is unavailable.
    • Two local static helper functions (GetLoadedClips and GetPlayingClips) are defined inside the method to fetch and format pool statistics.
    • Widgets are created using DebugUI types (Container, Value, Button) and ObservableList to supply their children.
    • Many values are displayed as formatted strings (time in milliseconds or bytes).
    • This method is private; the debug system is expected to locate it via the DebugTab attribute and reflection.
    • Dependencies/assumptions: AudioManager.instance, Radio API (GetActiveSource, GetAudioSourceTimeElapsed, GetAudioSourceDuration, GetAudioSourceTimeRemaining, Reload), FormatUtils, Time.timeSinceLevelLoad.

Usage Example

[DebugContainer]
public static class AudioDebugUI
{
    // The debug system discovers this method via the DebugTab attribute
    [DebugTab("Audio", -4)]
    private static List<DebugUI.Widget> BuildAudioDebugUI()
    {
        // Implementation builds DebugUI containers and widgets for radio and clips
    }
}

Notes / Tips: - You do not call BuildAudioDebugUI() directly — the debug framework discovers methods annotated with DebugTab inside classes annotated with DebugContainer. - The debug UI is read-only for most values; the "Reload" button invokes radio?.Reload() to force the radio subsystem to reload its data. - If you extend or modify this debug UI, keep null checks around AudioManager.instance and radio to prevent errors when audio systems are not initialized.