Game.UI.InGame.HealthcareVehicleSection
Assembly: Game
Namespace: Game.UI.InGame
Type: class
Base: VehicleSection
Summary:
UI section that displays information for healthcare vehicles (ambulances and medical helicopters). It determines visibility based on the selected entity's components, extracts the ambulance component to identify the currently targeted patient, selects the proper localization key (ambulance vs medical helicopter), and exposes JSON properties for the patient (both name and entity id) and the vehicle locale key. Intended for in-game vehicle UI in Cities: Skylines 2 modding; relies on the ECS EntityManager and several game-specific component types.
Fields
-
private Unity.Entities.Entity patientEntity { get; set; }
Tracks the patient entity targeted by the ambulance/helicopter. Initialized to Entity.Null in Reset(). Used when writing JSON properties and for UI display (via the name system). -
private VehicleLocaleKey vehicleKey { get; set; }
Holds the selected VehicleLocaleKey (VehicleLocaleKey.Ambulance or VehicleLocaleKey.MedicalHelicopter) depending on whether the selected prefab has HelicopterData. Added to tooltipKeys for localized display.
Properties
-
protected override string group => "HealthcareVehicleSection"
Group identifier used by the UI system to categorize this section. Override of the base VehicleSection.group. -
private Unity.Entities.Entity patientEntity { get; set; }
(See Fields) Private auto-property used internally to store the current patient entity. -
private VehicleLocaleKey vehicleKey { get; set; }
(See Fields) Private auto-property storing the locale key chosen for the vehicle type.
Constructors
public HealthcareVehicleSection()
Default constructor. Marked with [Preserve] to prevent stripping by code stripping systems. No custom initialization besides what base constructor and lifecycle methods handle.
Methods
-
protected override void Reset()
Resets the section state by calling base.Reset() and setting patientEntity to Entity.Null. Ensures stale patient data is cleared when the section is reused. -
private bool Visible()
Determines whether this section should be visible. Returns true only when the selected entity has Vehicle and Ambulance components and also has an Owner component. Used by OnUpdate to set base.visible. -
[Preserve] protected override void OnUpdate()
Called each update; sets base.visible by evaluating Visible(). Minimal update logic; actual UI population happens in OnProcess. -
protected override void OnProcess()
Main processing step for the section: - Reads the Ambulance component from the selectedEntity to obtain m_TargetPatient and assigns it to patientEntity.
- Sets base.stateKey using VehicleUIUtils.GetStateKey(selectedEntity, ambulanceComponent, EntityManager).
- Chooses vehicleKey: if the selected prefab has HelicopterData then VehicleLocaleKey.MedicalHelicopter, otherwise VehicleLocaleKey.Ambulance.
- Adds vehicleKey.ToString() to tooltipKeys so the UI can display the localized vehicle name.
-
Calls base.OnProcess() to complete processing and populate base UI state.
-
public override void OnWriteProperties(IJsonWriter writer)
Writes the section properties into a JSON writer for the UI frontend: - "patient": null if patientEntity == Entity.Null, otherwise use m_NameSystem.BindName(writer, patientEntity) to write the patient name object.
- "patientEntity": writes null or the raw entity id.
- "vehicleKey": writes the enum name (string) of the selected VehicleLocaleKey. Relies on the base class' m_NameSystem and IJsonWriter contract.
Usage Example
[Preserve]
protected override void OnProcess()
{
base.OnProcess(); // keep base processing if modifying behavior
// Example: read the patient entity set by this section and log its name if present
if (patientEntity != Unity.Entities.Entity.Null)
{
// m_NameSystem is provided by the base class (VehicleSection)
// This binds the name object into a JSON-like writer for UI; here we just illustrate usage
m_NameSystem.BindName(DebugJsonWriter.Instance, patientEntity);
}
}
Notes and remarks: - Dependencies: EntityManager, Vehicle, Game.Vehicles.Ambulance, Owner, HelicopterData, VehicleLocaleKey, VehicleUIUtils, m_NameSystem (from base VehicleSection), and IJsonWriter. - Visibility logic is strict: the section only appears for vehicles that are ambulances (or ambulance-type helicopters) and that have an Owner component. - When writing JSON, patient names are emitted via the game's name binding system to preserve name formatting and localization.