Game.ParkSection
Assembly:
Namespace: Game.UI.InGame
Type: public class
Base: InfoSectionBase
Summary:
UI info-section that displays maintenance information for a selected Park entity. The section becomes visible only when the currently selected entity has a Game.Buildings.Park component. It reads Park runtime component data and the corresponding ParkData prefab (via TryGetComponentWithUpgrades) to compute a maintenance percentage, stores it in a private auto-property, and exposes it through JSON writing for the UI. The class is marked with [CompilerGenerated]; several members are decorated with [Preserve] to avoid stripping.
Fields
- (none declared in this class)
This class uses an auto-property for storage (see Properties). Other data (selectedEntity, selectedPrefab, EntityManager, etc.) is provided by the base class InfoSectionBase.
Properties
-
protected override string group { get }
Returns the UI grouping name for this section. Implementation:=> "ParkSection"
. Used by the UI framework to identify the section/group. -
private int maintenance { get; set; }
Auto-property that stores the computed maintenance percentage for the selected park. It's reset to 0 in Reset(), updated in OnProcess(), and written out in OnWriteProperties().
Constructors
public ParkSection()
Has a [Preserve] attribute on the constructor. Default parameterless constructor — class initialization is handled by the UI/mod system.
Methods
-
protected override void Reset()
Resets transient state for the section. Implementation setsmaintenance = 0
. Called by the framework when the section should clear current state. -
private bool Visible()
Determines whether this section should be visible. Returns true when the currently selected entity has a Game.Buildings.Park component:base.EntityManager.HasComponent<Game.Buildings.Park>(selectedEntity)
. -
[Preserve] protected override void OnUpdate()
Called each update tick. The override sets the section visibility flag:base.visible = Visible();
-
protected override void OnProcess()
Core logic for updating displayed values. Attempts to get the Park prefab data usingTryGetComponentWithUpgrades<ParkData>(selectedEntity, selectedPrefab, out var data)
. If successful, reads runtime Park component data viabase.EntityManager.GetComponentData<Game.Buildings.Park>(selectedEntity).m_Maintenance
and computes a percentage: - If
data.m_MaintenancePool == 0
, uses 0 to avoid division. - Otherwise computes maintenance ratio = m_Maintenance / (float)data.m_MaintenancePool.
-
Multiplies by 100 and uses
Mathf.CeilToInt
to convert to an integer percent. The code usesmath.select
to handle the division-by-zero case. -
public override void OnWriteProperties(IJsonWriter writer)
Writes current properties for UI/serialization. Writes a property named"maintenance"
with the integer value of maintenance:
writer.PropertyName("maintenance");
writer.Write(maintenance);
Usage Example
[Preserve]
protected override void OnUpdate()
{
base.visible = Visible();
}
Notes and implementation details:
- The class depends on base members provided by InfoSectionBase such as selectedEntity, selectedPrefab, EntityManager, and TryGetComponentWithUpgrades