Skip to content

Game.UI.InGame.EducationSection

Assembly: Game
Namespace: Game.UI.InGame

Type: class

Base: InfoSectionBase

Summary:
UI information section used by the in-game building/info panel to display education-specific data for a selected school. It gathers runtime information (current student count, capacity, average graduation time and fail probability) from the selected entity and its prefab/upgrade data, then writes those values to the UI JSON payload via OnWriteProperties. The section becomes visible only when the selected entity has a School component.


Fields

  • This class does not declare public or explicit instance fields. It uses private auto-properties and inherited state from InfoSectionBase (e.g., selectedEntity, selectedPrefab, EntityManager).

Properties

  • protected override string group => "EducationSection"
    Identifies the UI group/key used by the base InfoSection system for grouping this section in the panel. Used by InfoSectionBase logic.

  • private int studentCount { get; set; }
    Runtime count of Student buffer entries on the selected entity. Updated in OnProcess by reading a DynamicBuffer from the entity (if present).

  • private int studentCapacity { get; set; }
    Student capacity read from the selected prefab's SchoolData (via TryGetComponentWithUpgrades). Represents how many students the school can accommodate (from prefab/upgrades).

  • private float graduationTime { get; set; }
    Average graduation time taken from the School component on the selected entity. If the component reports <= 0, a default of 0.5f is used.

  • private float failProbability { get; set; }
    Average fail probability read from the School component on the selected entity.


Constructors

  • public EducationSection()
    Default constructor. Marked with [Preserve] attribute on the class methods but not strictly required here; simple initializer only.

Methods

  • protected override void Reset()
    Resets the section's cached values (studentCount and studentCapacity) to zero. Called by the base InfoSection lifecycle when the section is reset.

  • private bool Visible()
    Returns true when the currently selected entity has the Game.Buildings.School component. Used to drive the section's visibility in the UI.

  • [Preserve] protected override void OnUpdate()
    Called each update tick by the InfoSection system. Sets base.visible based on the Visible() helper so the section is shown/hidden appropriately.

  • protected override void OnProcess()
    Core data-gathering method. Steps performed:

  • Attempts to get SchoolData (prefab data) including upgrades for the selected prefab/entity via TryGetComponentWithUpgrades. If successful, sets studentCapacity from data.m_StudentCapacity.
  • Reads a DynamicBuffer from the selected entity (read-only) and sets studentCount to buffer.Length if present.
  • Reads the Game.Buildings.School component from the selected entity and, if present, sets graduationTime (uses a fallback of 0.5f when m_AverageGraduationTime <= 0) and failProbability from component.m_AverageFailProbability.

Notes for modders: TryGetComponentWithUpgrades is used to take prefab upgrade variations into account when reading capacity. DynamicBuffer is used to get the live student count on the entity.

  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes the gathered values into the UI JSON payload. The method writes the following properties:
  • "studentCount" : studentCount
  • "studentCapacity" : studentCapacity
  • "graduationTime" : graduationTime
  • "failProbability" : failProbability

This JSON is consumed by the UI layer to display these values in the info panel.


Usage Example

[Preserve]
protected override void OnUpdate()
{
    base.OnUpdate();
    // show or hide the section based on whether a School component is present
    base.visible = base.EntityManager.HasComponent<Game.Buildings.School>(selectedEntity);
}

Additional notes for modders: - selectedEntity, selectedPrefab and EntityManager are provided by InfoSectionBase; use them to query entity components, buffers and prefab data. - Use TryGetComponentWithUpgrades when you want prefab values that respect applied upgrades. - DynamicBuffer gives the live list of student entries for the building entity; its Length is the current student count. - OnWriteProperties is the place to expose data to the UI — any fields written here will be available in the UI JSON for the front-end to render.