Skip to content

Game.Prefabs.AgeStatistic

Assembly:
Namespace: Game.Prefabs

Type: public class AgeStatistic

Base: ParametricStatistic

Summary:
Represents a statistic prefab that exposes age-group based parameters for population visualization (e.g., charts/legends). The class maps configured PopulationAgeGroupInfo entries to StatisticParameterData values (parameter id and color) that the statistics system can consume. It also provides a helper to turn a parameter id into a human-readable name using the CitizenAge enum. This component is decorated with [ComponentMenu] so it can be added/configured from the prefab/component menu in the editor.


Fields

  • public PopulationAgeGroupInfo[] m_AgeGroups
    Array of age-group definitions. Each element (PopulationAgeGroupInfo) describes a CitizenAge group and an associated color. The GetParameters() method iterates this array to produce statistic parameters. This field is public so it can be configured on the prefab (inspector) or set from code.

Properties

  • None declared on this class (inherits whatever members ParametricStatistic exposes).

Constructors

  • public AgeStatistic()
    No explicit constructor is defined in the source; the default parameterless constructor is provided by the runtime. Initialization of m_AgeGroups is expected to be done via the inspector or prefab initialization code.

Methods

  • public override IEnumerable<StatisticParameterData> GetParameters()
    Yields a StatisticParameterData instance for each configured entry in m_AgeGroups. For each non-null entry the method yields a parameter where the integer parameter id is the numeric value of the entry's CitizenAge group and the color is taken from the entry. The method uses yield return, so enumeration is deferred and does not create a large temporary collection.

  • public override string GetParameterName(int parameter)
    Returns the name of the CitizenAge enum value corresponding to the given parameter id by calling Enum.GetName(typeof(CitizenAge), parameter). Useful for generating labels/legends for UI elements.

Usage Example

// Example: iterate parameters produced by an AgeStatistic instance
AgeStatistic ageStat = /* obtain reference from prefab/component */;

foreach (var param in ageStat.GetParameters())
{
    // StatisticParameterData typically contains a numeric parameter id and a color.
    // Accessors depend on the actual StatisticParameterData implementation; assume:
    int paramId = param.param;   // replace with actual property name if different
    UnityEngine.Color color = param.color;

    string name = ageStat.GetParameterName(paramId);
    // Use 'name' and 'color' to build a legend or color map for UI
    Debug.Log($"Age group: {name} (id={paramId}), color={color}");
}

Notes and tips for modders: - Ensure m_AgeGroups is populated (via the prefab inspector or code) with the desired PopulationAgeGroupInfo elements; otherwise GetParameters() yields nothing. - GetParameters uses deferred execution (yield), so avoid mutating m_AgeGroups while enumerating. - GetParameterName relies on the CitizenAge enum; ensure the parameter ids produced match enum values.