Game.Debug.BaseDebugSystem
Assembly: Game
Namespace: Game.Debug
Type: abstract class
Base: GameSystemBase
Summary: BaseDebugSystem is an abstract base class intended for creating debug systems within the game. It provides a simple infrastructure for registering toggleable debug options (the nested Option class), lifecycle hooks (OnCreate, OnUpdate) integrated with Unity.Jobs.JobHandle dependency chaining, and methods called when the debug UI container is enabled or disabled. The class uses [Preserve] on important lifecycle methods/constructors to ensure they aren't stripped by code stripping in builds.
Fields
None (no private instance fields declared in this class)
BaseDebugSystem stores its state in properties and the nested Option objects rather than exposing private fields. Subclasses may declare their own fields as needed.
Properties
public System.Collections.Generic.List<BaseDebugSystem.Option> options { get; private set; }
This property holds the list of available debug options for the debug system. It is initialized in OnCreate() and can be read publicly but only set by the class itself. Each entry is an instance of the nested Option class which represents a named toggleable setting.
Nested Option members (for reference):
- public string name { get; private set; }
— Display name for the option.
- public bool enabled { get; set; }
— Current enabled/disabled state.
Constructors
-
protected BaseDebugSystem()
The protected constructor is marked [Preserve]. It does no special work itself; initialization occurs in OnCreate(). Use this when deriving a concrete debug system. -
public Option(string displayName, bool defaultEnabled)
(nested class constructor)
Creates a new Option instance with the given display name and default enabled state. Option.name is read-only (private set), Option.enabled is mutable.
Methods
protected override void OnCreate()
Called during system creation. This override calls the base implementation and initializes the options list:- It should call base.OnCreate() first.
-
Initializes options = new List
-
protected Option AddOption(string displayName, bool defaultEnabled)
Helper to create and register a new Option. Returns the created Option so derived classes can keep a reference to manipulate default state or read the enabled flag. -
[Preserve] protected override void OnUpdate()
The parameterless override integrates with the system's job dependency handling by assigning base.Dependency = OnUpdate(base.Dependency). This ensures the JobHandle returned from the virtual OnUpdate(JobHandle) is recorded as the system's dependency. -
[Preserve] protected virtual Unity.Jobs.JobHandle OnUpdate(Unity.Jobs.JobHandle inputDeps)
Virtual method intended to be overridden by derived debug systems to schedule jobs or perform update work. Must return a JobHandle representing work to chain into the system. The default implementation simply returns the inputDeps unchanged. -
public virtual void OnEnabled(DebugUI.Container container)
Called when the debug UI container for this system is enabled. Override to add UI elements (for example, toggles bound to the Option entries) into the provided container. Default implementation is empty. -
public virtual void OnDisabled(DebugUI.Container container)
Called when the debug UI container is disabled/removed. Override to perform cleanup related to UI or other enabled-only behavior. Default implementation is empty.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Initialize options list and register options
options = new List<Option>();
AddOption("ShowGrid", false);
AddOption("ShowNavPaths", true);
}
[Preserve]
protected override void OnUpdate()
{
// Ensure job dependency chaining is preserved by using the virtual OnUpdate(JobHandle)
base.Dependency = OnUpdate(base.Dependency);
}
[Preserve]
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
// Derived systems can schedule jobs here and return a combined JobHandle.
return inputDeps;
}
public override void OnEnabled(DebugUI.Container container)
{
// Example: add toggle controls to the debug UI based on registered options
foreach (var opt in options)
{
// pseudo-code for adding UI; actual API depends on DebugUI implementation
// container.AddToggle(opt.name, value => opt.enabled = value, opt.enabled);
}
}