Game.Debug.TradeCostDebugSystem
Assembly:
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: Provides an in-editor debug system that visualizes trade buy/sell costs for resources by drawing gizmos (wire cubes) at entities that have TradeCost buffers (e.g., warehouses / company prefabs). Exposes UI options to switch the resource to visualize and to filter between storage prefabs (warehouses) and companies. Uses a parallel IJobChunk (TradeCostGizmoJob) and the engine's GizmosSystem to batch draw gizmos efficiently.
Fields
-
private EntityQuery m_StorageGroup
Used to query all entities that have a TradeCost buffer and are not Deleted / Temp / Hidden. If this query is empty the system early-outs on update. -
private GizmosSystem m_GizmosSystem
Reference to the world's GizmosSystem used to obtain a GizmoBatcher for drawing batched gizmos from jobs and to register the job writer. -
private Resource m_SelectedResource
The currently selected Resource to visualize (default set to Resource.Grain in OnCreate). This is changed through the debug UI. -
private Option m_StorageOption
Debug UI toggle option that filters/controls whether storage prefabs (warehouses) are included. Initialized via AddOption("Warehouses", defaultEnabled: true). -
private Option m_CompanyOption
Debug UI toggle option that filters/controls whether company prefabs are included. Initialized via AddOption("Companies", defaultEnabled: false). -
private TypeHandle __TypeHandle
Container for all Entity / Buffer / Component lookup handles used by the job. Populated during OnCreateForCompiler by calling __AssignHandles. (See nested TypeHandle struct below.) -
private struct TradeCostGizmoJob
IJobChunk that performs the per-chunk work to read TradeCost buffers and draw gizmos: - Reads entity, TradeCost buffer, PrefabRef and optional PropertyRenter components.
- Uses ComponentLookup
to get world positions/rotations for drawing. - Uses ComponentLookup
to filter prefab types when the Storage/Company options are toggled. - Uses GizmoBatcher to draw wire cubes representing buy / sell cost heights and colors (green → red gradient).
- For rented properties (PropertyRenter present) it uses the rented property's transform instead of the entity's transform and logs if the transform is missing.
-
Scheduled in parallel over m_StorageGroup; the system obtains a GizmoBatcher and dependency handle from GizmosSystem.
-
private struct TypeHandle
Holds the various type handles and lookups used by the job and a helper to assign them: - Fields:
- EntityTypeHandle __Unity_Entities_Entity_TypeHandle
- BufferTypeHandle
__Game_Companies_TradeCost_RO_BufferTypeHandle - ComponentTypeHandle
__Game_Buildings_PropertyRenter_RO_ComponentTypeHandle - ComponentTypeHandle
__Game_Prefabs_PrefabRef_RO_ComponentTypeHandle - ComponentLookup
__Game_Objects_Transform_RO_ComponentLookup - ComponentLookup
__Game_Prefabs_StorageCompanyData_RO_ComponentLookup
- Method:
- __AssignHandles(ref SystemState state): fills the above handles/lookups from the given SystemState (called during system initialization).
Properties
- (none public)
This system does not expose public C# properties. It exposes two debug Options (m_StorageOption and m_CompanyOption) through the BaseDebugSystem API and uses internal fields for state.
Constructors
public TradeCostDebugSystem()
Default constructor. The system initialization and handle assignment are performed in OnCreate and OnCreateForCompiler; constructor itself does not perform runtime setup.
Methods
protected override void OnCreate()
Initializes the debug system:- Calls base.OnCreate().
- Adds two UI options: "Warehouses" (enabled by default) and "Companies" (disabled by default).
- Gets the GizmosSystem from the world.
- Builds the EntityQuery m_StorageGroup to select entities with TradeCost buffer and exclude Deleted / Temp / Hidden.
- Disables the system by default (base.Enabled = false).
-
Sets the default selected resource to Resource.Grain.
-
public override void OnEnabled(DebugUI.Container container)
Populates the debug UI when the system is enabled: - Adds an EnumField named "Resource" that displays and lets the user pick the resource to visualize.
-
The enum field maps editor indices to in-game Resource values using EconomyUtils.GetResource and GetResourceIndex.
-
protected override JobHandle OnUpdate(JobHandle inputDeps)
Schedules the TradeCostGizmoJob (IJobChunk) to draw gizmos: - If m_StorageGroup.IsEmptyIgnoreFilter, returns the input dependency immediately.
- Obtains required type handles via InternalCompilerInterface.Get* wrappers (using __TypeHandle and base.CheckedStateRef).
- Calls m_GizmosSystem.GetGizmosBatcher(out dependencies) to get a GizmoBatcher and an associated dependency handle required by the batcher.
- Schedules the TradeCostGizmoJob in parallel over m_StorageGroup, combining inputDeps with the gizmo dependency.
- Registers the returned job handle with m_GizmosSystem via AddGizmosBatcherWriter so gizmo writes are synchronized.
-
Returns the scheduled job handle.
-
private void __AssignQueries(ref SystemState state)
Called by the compiler helper OnCreateForCompiler to set up any queries needed at compile-time. In this implementation it currently only instantiates and disposes a temporary EntityQueryBuilder (no runtime effect). -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries and then assigns type handles via __TypeHandle.__AssignHandles. Ensures the system's type handles are ready for the job scheduling paths that use InternalCompilerInterface.
Usage Example
// Enable the debug system and show trade cost gizmos for the default resource (Grain):
var tradeDebug = world.GetOrCreateSystemManaged<Game.Debug.TradeCostDebugSystem>();
tradeDebug.Enabled = true;
// The debug UI (opened via the game's debug menu) lets you:
// - pick the Resource to visualize
// - toggle "Warehouses" and "Companies" filters
// Gizmos will be drawn automatically each frame by the scheduled TradeCostGizmoJob.