Game.TerrainDebugSystem
Assembly:
Game (Game.dll)
Namespace:
Game.Debug
Type:
public class
Base:
GameSystemBase
Summary:
TerrainDebugSystem is a debug-only game system used to visualize terrain-related data in the editor/game (cascades, culled regions and road lane sections). It exposes an in-game GUI (via RenderDebugUI) to switch between Cascade and World debug modes and draws bounding boxes for terrain cascades, viewports, cull areas and road lane sections using Colossal.Gizmos. The system depends on TerrainSystem and TerrainRenderSystem and starts disabled by default.
Fields
-
private DebugMode m_Mode
Tracks the current debug mode (Cascade or World). Controls which UI and debug geometry are shown. -
private TerrainSystem m_TerrainSystem
Reference to the TerrainSystem instance retrieved from the World on creation. Used to read cascade slice areas, world/playable sizes, road lane sections, and cascade update flags. -
private TerrainRenderSystem m_TerrainRenderSystem
Reference to the TerrainRenderSystem instance retrieved from the World on creation. Used to query cascade regions, viewports and last cull area for visualization. -
public enum DebugViewMode { LODLevel, TreePosition }
Internal enum declared in the class. Present for potential future/alternate debug visualizations (not used in current code paths). -
public enum DebugMode { Cascade, World }
Enum used by m_Mode to select between cascade debug drawing and world information UI.
Properties
This class does not expose any public properties.
Constructors
public TerrainDebugSystem()
Constructor marked with [Preserve]. No special initialization is performed here; actual setup occurs in OnCreate. The system is left disabled by default (OnCreate sets base.Enabled = false).
Methods
-
protected override void OnCreate() : System.Void
[Preserve] Called when the system is created. Retrieves and caches references to TerrainSystem and TerrainRenderSystem via base.World.GetOrCreateSystemManaged<>() and sets base.Enabled = false (system is off by default). Use this method to find required dependencies. -
protected override void OnDestroy() : System.Void
[Preserve] Tear-down logic placeholder. The current implementation just calls base.OnDestroy(). -
protected override void OnUpdate() : System.Void
[Preserve] Called each frame when the system is enabled. It invokes DrawDebug() which performs debug drawing depending on the selected mode. -
private void DrawDebug() : System.Void
Internal routine that chooses debug drawing behavior based on m_Mode. When in DebugMode.Cascade it calls DrawRoads() and DrawCascades(). -
public void RenderDebugUI() : System.Void
Renders an immediate-mode GUI (GUILayout) for toggling debug mode and displaying cascade/world information. Buttons allow switching between Cascade and World modes. In Cascade mode it shows cascade slice sizes, viewports and a toggle to freeze cascade updates. In World mode it prints world/playable sizes and offsets. -
private void DrawRoads() : System.Void
Fetches lane sections from TerrainSystem.GetRoads(), constructs 3D bounding boxes around each lane section (taking lane heights into account) and draws wireframe bounds with different colors depending on flags and whether they intersect the last cull area or the cascade region. Uses Colossal.Gizmos.batcher.DrawWireBounds. -
private void DrawCascades() : System.Void
Iterates through the 4 cascade indices and draws their cascade regions. If a slice was updated last frame, it additionally draws the cascade viewport and cascade cull area. Also draws the last cull area for the terrain render system.
Usage Example
// Example: enable and use the TerrainDebugSystem from a mod's initialization or debug UI
var debugSystem = World.Instance.GetOrCreateSystemManaged<Game.Debug.TerrainDebugSystem>();
debugSystem.Enabled = true;
// In a MonoBehaviour.OnGUI() or similar debug UI callback, call:
debugSystem.RenderDebugUI();
// The system will perform per-frame debug drawing in its OnUpdate() while Enabled == true.
Notes and tips: - The system is disabled by default in OnCreate, so enable it explicitly to see debug draws. - RenderDebugUI uses immediate mode GUILayout; call it from an OnGUI-like context. - The class depends on TerrainSystem and TerrainRenderSystem; ensure those systems exist in the world before enabling this debug system.