Game.UI.InGame.HealthcareSection
Assembly:
Game (inferred)
Namespace:
Game.UI.InGame
Type:
class
Base:
InfoSectionBase
Summary:
Provides a UI info section that reports healthcare-related statistics for a selected healthcare building (hospitals). It tracks current patient count and configured patient capacity from the building prefab/upgrades and exposes those values to the UI JSON writer. The section becomes visible only when a patient capacity > 0 is present on the selected entity.
Fields
-
private int <patientCount>k__BackingField
Compiler-generated backing field for the private auto-property patientCount. Holds the current number of patients read from the entity's Patient buffer. -
private int <patientCapacity>k__BackingField
Compiler-generated backing field for the private auto-property patientCapacity. Holds the patient capacity read from the building data (HospitalData).
Properties
-
protected override string group => "HealthcareSection"
Identifies the UI group/name used by the base InfoSectionBase. This is a constant override returning "HealthcareSection". -
private int patientCount { get; set; }
Tracks the current number of patients associated with the selected entity. Updated in OnProcess by reading the DynamicBufferlength. -
private int patientCapacity { get; set; }
Tracks the patient capacity reported by the selected hospital prefab (including upgrades). Updated in OnUpdate when the selected entity is a Hospital and its HospitalData is available.
Constructors
public HealthcareSection()
Default parameterless constructor. Marked with [Preserve] on the type methods to avoid stripping by code stripping tools; constructor itself is empty.
Methods
-
protected override void Reset()
Resets runtime-tracked values (patientCount and patientCapacity) to 0. Called by the base lifecycle when the section is initialized/cleared. -
protected override void OnUpdate()
Checks whether the currently selected entity has a Game.Buildings.Hospital component and attempts to retrieve the HospitalData (including upgrades) for the selected prefab. If successful, sets patientCapacity = data.m_PatientCapacity. Updates base.visible to (patientCapacity > 0), making the section visible only when capacity is present.
Notes:
- Uses base.EntityManager.HasComponent
-
protected override void OnProcess()
Attempts to read a DynamicBufferfrom the selected entity. If present, sets patientCount to buffer.Length (current number of patient entries). This provides up-to-date patient counts each process/frame for the UI. -
public override void OnWriteProperties(IJsonWriter writer)
Writes the tracked properties to the provided IJsonWriter: - "patientCount" -> patientCount
- "patientCapacity" -> patientCapacity
This is how the UI consumes the values for rendering.
Usage Example
[Preserve]
protected override void OnUpdate()
{
// Example snippet similar to HealthcareSection behavior:
if (EntityManager.HasComponent<Game.Buildings.Hospital>(selectedEntity)
&& TryGetComponentWithUpgrades<HospitalData>(selectedEntity, selectedPrefab, out var data))
{
patientCapacity = data.m_PatientCapacity;
}
base.visible = patientCapacity > 0;
}
protected override void OnProcess()
{
if (EntityManager.TryGetBuffer(selectedEntity, isReadOnly: true, out DynamicBuffer<Patient> buffer))
{
patientCount = buffer.Length;
}
}
public override void OnWriteProperties(IJsonWriter writer)
{
writer.PropertyName("patientCount");
writer.Write(patientCount);
writer.PropertyName("patientCapacity");
writer.Write(patientCapacity);
}
Additional notes: - The class depends on the ECS EntityManager API (Unity.Entities) and game-specific types: Game.Buildings.Hospital, HospitalData, and Patient buffer type. - TryGetComponentWithUpgrades is used to obtain prefab data including applied upgrades — ensure that method is available in the base class or utility scope when adapting this pattern. - The [Preserve] attribute is used on methods to prevent code stripping for runtime reflection/serialization.