Game.UI.InGame.ComfortSection
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
UI info section that displays the "comfort" value for certain in-game entities (transport stops, transport stations and parking facilities). It determines whether the section should be visible for the currently selected entity, reads the appropriate component's comfort factor, converts it to a percentage, and exposes that value for JSON serialization (used by the UI).
Fields
private int comfort
Private backing auto-property (stores the computed comfort percentage as an integer).
Properties
-
protected override string group => "ComfortSection"
Returns the group/name used to identify this info section in the UI system. -
private int comfort { get; set; }
Auto-property holding the computed comfort percentage (0–100). Note: declared private; used internally and written out via OnWriteProperties.
Constructors
public ComfortSection()
Default constructor. Marked with [Preserve] on the class/methods to keep the method during IL stripping.
Methods
-
protected override void Reset()
Resets internal state. Sets comfort to 0. -
private bool Visible()
Determines whether the comfort section should be visible for the currently selected entity. Visibility logic: - If the selected entity has a MailBox component, visible.
- Otherwise, if it has a TransportStop component -> visible.
- Otherwise, if it has a TransportStation component and that component is a PublicTransportStation -> visible.
-
Otherwise, visible only if the selected entity has a ParkingFacility component. In short: visible for transport stops, transport stations (public stations), mailboxes and parking facilities.
-
[Preserve] protected override void OnUpdate()
Called regularly by the UI system. Sets base.visible based on Visible(). -
protected override void OnProcess()
Reads the entity components to obtain the comfort factor: - If entity has TransportStop: uses component.m_ComfortFactor and adds "TransportStop" tooltip key.
- Else if it has TransportStation: uses component.m_ComfortFactor and adds "TransportStation" tooltip key.
-
Else if it has ParkingFacility: uses component.m_ComfortFactor and adds "Parking" tooltip key. The float comfort factor (range 0.0–1.0) is multiplied by 100 and rounded to the nearest integer and stored in comfort.
-
public override void OnWriteProperties(IJsonWriter writer)
Writes the computed comfort to JSON under the property name "comfort": writer.PropertyName("comfort"); writer.Write(comfort);
Usage Example
[Preserve]
protected override void OnUpdate()
{
base.visible = Visible(); // ensure UI visibility follows entity type rules
}
protected override void OnProcess()
{
// Example: read comfort (this mirrors what the built-in implementation does)
float factor = 0f;
if (EntityManager.TryGetComponent<TransportStop>(selectedEntity, out var stop))
{
factor = stop.m_ComfortFactor;
}
else if (EntityManager.TryGetComponent<TransportStation>(selectedEntity, out var station))
{
factor = station.m_ComfortFactor;
}
else if (EntityManager.TryGetComponent<ParkingFacility>(selectedEntity, out var parking))
{
factor = parking.m_ComfortFactor;
}
comfort = (int)Unity.Mathematics.math.round(100f * factor);
}
Notes: - The class uses component lookups on the selected entity via EntityManager.TryGetComponent / HasComponent. - The comfort value is exposed to the UI/serialization via OnWriteProperties as an integer percent (0–100). - Attributes like [Preserve] and [CompilerGenerated] are present to control linking/IL stripping and compiler behavior.