Game.Prefabs.StatisticsPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ArchetypePrefab
Summary:
StatisticsPrefab is a prefab definition used to create UI/statistics entities for Cities: Skylines 2. It holds references to UI category/group prefabs and configuration for which statistic to display (type, collection, unit, color and whether it should be stacked). At initialization it writes a StatisticsData component to the entity and the archetype includes a CityStatistic component. It also provides a helper CreateInstance method to instantiate configured statistic entities at runtime.
Fields
-
public UIStatisticsCategoryPrefab m_Category
Reference to the UI statistics category prefab this statistic belongs to. Used in LateInitialize to set the StatisticsData.m_Category field. -
public UIStatisticsGroupPrefab m_Group
Reference to the UI statistics group prefab. Used in LateInitialize to set the StatisticsData.m_Group field. -
public StatisticType m_StatisticsType
Specifies which statistic (enum) this prefab represents. Copied into StatisticsData.m_StatisticType during LateInitialize. -
public StatisticCollectionType m_CollectionType
Specifies how the statistic is collected/aggregated. Copied into StatisticsData.m_CollectionType during LateInitialize. -
public StatisticUnitType m_UnitType
Unit type for the statistic (e.g., count, percentage). Copied into StatisticsData.m_UnitType during LateInitialize. -
public Color m_Color = Color.grey
Display color for the statistic in the UI. Default is grey. Assigned to StatisticsData.m_Color. -
public bool m_Stacked = true
Whether this statistic should be stacked with other series in UI displays. Default true. Assigned to StatisticsData.m_Stacked.
Properties
- None.
Constructors
public StatisticsPrefab()
The class does not declare a custom constructor; it uses the default parameterless constructor inherited from MonoBehaviour/ArchetypePrefab (depending on runtime). Initialization of prefab-specific fields is typically done via the inspector or in LateInitialize when the prefab is converted to entities.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the components required by the prefab instances. This override calls base then adds a read/write StatisticsData component type so instances will have StatisticsData. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds components required on the archetype for instances created from this prefab. This override calls base then adds a read/write CityStatistic component type to the archetype. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Finalizes the entity created from this prefab. It: - Resolves the referenced UIStatisticsCategoryPrefab and UIStatisticsGroupPrefab into their corresponding entities (via the PrefabSystem).
- Builds a StatisticsData struct populated from the prefab fields (group, category, collection/type/unit, color, stacked).
-
Writes the StatisticsData to the provided entity using entityManager.SetComponentData.
-
public static Entity CreateInstance(EntityManager entityManager, Entity entity, ArchetypeData archetypeData, int parameter = 0)
Creates a runtime instance of this prefab: - Creates a new entity using the provided archetype (archetypeData.m_Archetype).
- Adds a PrefabRef component to the new entity pointing back to the prefab entity.
- If the new entity has a StatisticParameter component, sets its m_Value to the provided parameter.
- Returns the newly created entity.
Usage Example
// Create an instance of the prefab at runtime with an optional parameter.
Entity instance = StatisticsPrefab.CreateInstance(entityManager, prefabEntity, archetypeData, parameterValue);
// When the prefab is converted / initialized, LateInitialize will populate the StatisticsData:
// (Internally called by the prefab conversion system)