Game.Prefabs.IncomeStatistic
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ParametricStatistic
Summary:
IncomeStatistic is a ParametricStatistic component used to represent various income sources in the game's statistics UI. It is attributed with [ComponentMenu("Statistics/", ...)] so it appears under the Statistics prefab menu in the editor. The component exposes an array of IncomeSourceInfo entries (each describing an income source and a color) and provides parameter data and parameter names used by the parent statistics system to render per-source data.
Fields
public IncomeSourceInfo[] m_Incomes
Holds the configured income sources for this statistic. Each element is expected to contain at least:- m_IncomeSource — an IncomeSource enum value identifying the source.
- m_Color — a color used to represent that source in charts/legends. If m_Incomes is null or empty, GetParameters() yields no entries.
Properties
- This class does not declare any public properties of its own. It inherits any properties from ParametricStatistic.
Constructors
public IncomeStatistic()
The default parameterless constructor (implicit in the C# source). No custom construction logic is defined in the class itself.
Methods
-
public override IEnumerable<StatisticParameterData> GetParameters()
Iterates the m_Incomes array (if not null) and yields a StatisticParameterData for each configured income source. For each entry it yields new StatisticParameterData((int)m_Incomes[i].m_IncomeSource, m_Incomes[i].m_Color). The method uses C# iterator (yield return). If m_Incomes is null the enumeration is empty. -
public override string GetParameterName(int parameter)
Returns the name of the IncomeSource enum value corresponding to the provided integer parameter by calling Enum.GetName(typeof(IncomeSource), parameter). If the integer does not map to a defined enum name this call may return null.
Notes: - The class relies on the IncomeSource enum and the IncomeSourceInfo type (not defined in this file). IncomeSourceInfo is expected to contain at least an IncomeSource value and a color field. - The component is suitable for use in prefabs or for runtime configuration; the statistics system consumes the yielded StatisticParameterData values to display labels/colors and to associate data series with income sources.
Usage Example
// Example: configuring an IncomeStatistic instance programmatically
var incomeStat = new Game.Prefabs.IncomeStatistic();
incomeStat.m_Incomes = new IncomeSourceInfo[]
{
new IncomeSourceInfo { m_IncomeSource = IncomeSource.Tax, m_Color = Color.green },
new IncomeSourceInfo { m_IncomeSource = IncomeSource.ServiceFees, m_Color = Color.cyan },
};
// Enumerate parameters produced for the statistics system
foreach (var param in incomeStat.GetParameters())
{
// param.parameterId == (int)IncomeSource.*
// param.color == the configured color
Debug.Log($"Parameter {param.parameterId} color {param.color}");
}
// Get the display name for a parameter id
string name = incomeStat.GetParameterName((int)IncomeSource.Tax);
Debug.Log($"Parameter name: {name}");