Game.UI.InGame.DisasterInfoviewUISystem
Assembly: Assembly-CSharp / Game
Namespace: Game.UI.InGame
Type: class
Base: InfoviewUISystemBase
Summary:
This ECS system backs the in-game disaster info UI panel for emergency shelters. It queries building entities that have EmergencyShelter components and computes the total sheltered count, total shelter capacity and an availability indicator. The computation is performed with a Burst-compiled IJobChunk (UpdateDisasterResponseJob) that aggregates occupant counts and shelter capacities using a NativeAccumulator for thread-safe accumulation. The system exposes UI bindings (ValueBinding) under the "disasterInfo" group: "shelteredCount", "shelterCapacity" and "shelterAvailability". It is optimized to only recompute when the relevant queries report modifications and uses synchronous completion of the job to update the UI bindings on the main thread.
Fields
-
private ValueBinding<int> m_ShelteredCount
Binding for the number of people currently sheltered (binding key: "disasterInfo", "shelteredCount"). Updated each PerformUpdate run with the aggregated occupant count. -
private ValueBinding<int> m_ShelterCapacity
Binding for the total shelter capacity across all emergency shelters (binding key: "disasterInfo", "shelterCapacity"). Updated each PerformUpdate run with aggregated capacity. -
private ValueBinding<IndicatorValue> m_ShelterAvailability
Binding representing shelter availability as an IndicatorValue (binding key: "disasterInfo", "shelterAvailability"). Constructed from capacity and current sheltered count to show available spots etc. -
private NativeAccumulator<UpdateDisasterResponseJob.Result> m_Result
Accumulator used by the Burst IJobChunk to accumulate per-chunk results (counts and capacities) in a thread-safe way. Allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy. -
private EntityQuery m_SheltersQuery
EntityQuery selecting Building + EmergencyShelter entities (excluding Deleted and Temp). Used to schedule the UpdateDisasterResponseJob. -
private EntityQuery m_SheltersModifiedQuery
EntityQuery that matches Building + EmergencyShelter and any of Deleted/Created/Updated (excluding Temp). Used by the system to detect modifications so updates can be skipped when nothing changed. -
private TypeHandle __TypeHandle
Internal struct that caches ComponentTypeHandle/BufferTypeHandle and ComponentLookup handles required by the job. Assigned in OnCreateForCompiler.
Properties
-
protected override bool Active
Determines whether the system is active for UI binding. Returns true if base.Active is true or any of the three ValueBindings (m_ShelterAvailability, m_ShelterCapacity, m_ShelteredCount) are active. This ensures the system remains active while the UI is using the bindings. -
protected override bool Modified
Returns true when m_SheltersModifiedQuery is not empty (IsEmptyIgnoreFilter == false). Used by the parent UI system base to avoid unnecessary PerformUpdate calls when nothing relevant has changed.
Constructors
public DisasterInfoviewUISystem()
Default constructor. Typical Unity ECS systems are constructed by the runtime; no custom parameters here.
Methods
protected override void OnCreate()
Initializes queries and UI bindings. Creates two EntityQuery objects:- m_SheltersQuery for all active emergency shelter buildings
-
m_SheltersModifiedQuery for detecting changes to those buildings Adds three ValueBinding instances for sheltered count, capacity, and availability, and allocates the m_Result NativeAccumulator with Persistent allocator.
-
protected override void OnDestroy()
Disposes the NativeAccumulator (m_Result) and calls base.OnDestroy(). -
protected override void PerformUpdate()
Main update path invoked by the UI system when active or modified. Clears the accumulator, schedules a Burst-compiled UpdateDisasterResponseJob over m_SheltersQuery, completes it synchronously, retrieves the aggregated Result, and updates the three ValueBindings: - m_ShelteredCount.Update(result.m_Count)
- m_ShelterCapacity.Update(result.m_Capacity)
- m_ShelterAvailability.Update(new IndicatorValue(0f, result.m_Capacity, result.m_Capacity - result.m_Count))
Note: the job is scheduled and immediately Complete()'d so results are available on the main thread for binding updates.
-
private void __AssignQueries(ref SystemState state)
Compiler helper used to set up queries at compile-time. In this decompiled layout it only constructs and disposes an EntityQueryBuilder; primary query setup is performed in OnCreate. -
protected override void OnCreateForCompiler()
Compiler-time initialization helper which assigns cached type handles via __TypeHandle.__AssignHandles and calls __AssignQueries. Part of generated bindings between IL2CPP/ECS internals and the system. -
Nested:
UpdateDisasterResponseJob : IJobChunk
(Burst-compiled) - Purpose: iterate over chunks of shelter-building entities and accumulate occupant counts and capacities.
- Key fields passed in: ComponentTypeHandle
, BufferTypeHandle , BufferTypeHandle , BufferTypeHandle , ComponentLookup , ComponentLookup , and NativeAccumulator . - Work: For each entity in the chunk, if efficiency != 0, it retrieves EmergencyShelterData via prefabs lookup, applies installed upgrades to modify stats (UpgradeUtils.CombineStats), and accumulates occupant length and shelter capacity into the accumulator.
- Result struct: contains m_Count and m_Capacity and implements IAccumulable
for accumulation across threads/chunks.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The system already creates its ValueBindings for "disasterInfo":
// "shelteredCount" (int), "shelterCapacity" (int), "shelterAvailability" (IndicatorValue).
// No additional initialization required for typical usage.
}
Additional notes: - Performance: the system uses Burst + IJobChunk and NativeAccumulator to perform efficient parallel aggregation. It deliberately completes the job before updating UI bindings to keep UI data consistent on the main thread. - Modding tip: You can read the UI binding keys ("disasterInfo", "shelteredCount"/"shelterCapacity"/"shelterAvailability") if integrating custom UI elements or debugging shelter stats. If adding custom shelter-related components or upgrades, ensure they are integrated into the prefab EmergencyShelterData / Upgrade system so the job's lookup and UpgradeUtils.CombineStats pick up the changes.