Skip to content

Game.Debug.AssetDatabaseDebugUI

Assembly: Game
Namespace: Game.Debug

Type: class

Base: IDisposable

Summary: A debug UI helper that builds an in-game debugging panel for inspecting the AssetDatabase and its change event handlers. It subscribes to global AssetDatabase change events to trigger UI rebuilds when databases are registered/unregistered, and exposes information such as global and per-database asset counts, hostnames, active handler lists, and action buttons (Apply settings, Reset settings, Refresh).


Fields

  • None (the class does not declare instance fields) {{ The class relies entirely on local variables and framework-managed event lists; it does not store state beyond subscribing to AssetDatabase.global.onAssetDatabaseChanged in the constructor. }}

Properties

  • None {{ This debug helper exposes no public properties. All UI construction is performed when BuildAssetDatabaseDebugUI is invoked by the DebugSystem. }}

Constructors

  • public AssetDatabaseDebugUI() {{ Subscribes to AssetDatabase.global.onAssetDatabaseChanged with a Rebuild callback. The subscription includes a predicate filter that only triggers for ChangeType.DatabaseRegistered and ChangeType.DatabaseUnregistered, ensuring UI rebuilds occur when databases are added/removed. }}

Methods

  • public void Dispose() : System.Void {{ Unsubscribes the Rebuild callback from AssetDatabase.global.onAssetDatabaseChanged. Call this when the debug UI is no longer needed to avoid leaking subscriptions. }}

  • private void Rebuild(AssetChangedEventArgs args = default(AssetChangedEventArgs)) : System.Void {{ Calls DebugSystem.Rebuild with the BuildAssetDatabaseDebugUI delegate to rebuild the debug UI. The method is invoked both by the event subscription and by the Refresh button. }}

  • [DebugTab("Asset Database", -20)] private List<DebugUI.Widget> BuildAssetDatabaseDebugUI() {{ Builds and returns a list of DebugUI widgets that represent:

  • A container with a foldout listing global database information:
    • Global mip bias, asset count, hostname
    • A foldout enumerating active global asset-database-change handlers (handler name entries)
  • Per-database foldouts listing each database's name, asset count and hostname and that database's active change handlers
  • Buttons for "Apply settings" (calls GameManager.instance.settings.Apply()), "Reset settings" (calls Reset()), and "Refresh" (calls Rebuild()). The method reads AssetDatabase.global and iterates its databases and handler collections to populate the UI. The DebugTab attribute places this UI under the "Asset Database" tab with the specified order. }}

Usage Example

// Create the debug UI (constructor subscribes to db change events).
var assetDbDebug = new Game.Debug.AssetDatabaseDebugUI();

// If you need to remove it (for example on teardown):
assetDbDebug.Dispose();

// The UI itself is constructed by DebugSystem.Rebuild calling BuildAssetDatabaseDebugUI.
// You can also force a rebuild programmatically:
assetDbDebug.GetType().GetMethod("Rebuild", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
    .Invoke(assetDbDebug, new object[] { default(Colossal.IO.AssetDatabase.AssetChangedEventArgs) });

{{ Notes: - The class depends on the following game systems/types: AssetDatabase (and IAssetDatabase), AssetChangedEventArgs, ChangeType, DebugSystem, DebugUI, GameManager, and EventDelegate handler collections. - The constructor filters subscription events to only DatabaseRegistered and DatabaseUnregistered to avoid rebuilding the UI on every asset change. - The DebugUI widgets created are read-only and reflect runtime state; pressing Apply/Reset will affect GameManager.instance.settings. - Because BuildAssetDatabaseDebugUI is private and invoked via DebugSystem.Rebuild, integration occurs through the debug system rather than direct UI placement. }}