Game.Prefabs.UIStatisticsGroupPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: public class
Base: UIGroupPrefab
Summary:
A prefab class used to define a statistics group in the UI. Holds display settings (color, unit type, stacked flag) and a reference to a UIStatisticsCategoryPrefab. At build time it registers the UIStatisticsGroupData component for entities created from this prefab and, during LateInitialize, resolves the referenced category prefab to an entity and writes UIStatisticsGroupData to the created entity. The class is decorated with a ComponentMenu attribute ("UI/") for Unity editor integration.
Fields
-
public UnityEngine.Color m_Color
Stores the display color for the statistics group. Default value is Color.black (set in-field). -
public UIStatisticsCategoryPrefab m_Category
Optional reference to a UIStatisticsCategoryPrefab. When present, this prefab is added as a dependency and resolved to an Entity in LateInitialize. -
public StatisticUnitType m_UnitType
Enum value describing the unit type used by the group (e.g., currency, percent, count). Stored in the UIStatisticsGroupData component on the entity. -
public bool m_Stacked
If true, the group's data should be presented in a stacked manner in the UI. Value is copied into UIStatisticsGroupData during LateInitialize.
Properties
None
This prefab exposes no CLR properties. Its configuration is via public fields and the runtime state is written into the UIStatisticsGroupData component on the Entity.
Constructors
public UIStatisticsGroupPrefab()
Default constructor (implicit). Field defaults: m_Color = Color.black (explicit in field), m_Category = null, m_UnitType = default(StatisticUnitType), m_Stacked = false. Unity serialization constructs this prefab in the editor/build pipeline.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required ECS component types for entities created from this prefab. Calls base.GetPrefabComponents(...) and then adds ComponentType.ReadWrite() so the runtime entity will contain UIStatisticsGroupData. -
public override void GetDependencies(List<PrefabBase> prefabs)
Collects prefab dependencies. Calls base.GetDependencies(...) and if m_Category is set, adds that prefab to the dependency list so it will be created/resolved before or along with this prefab. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Performs post-creation initialization on the entity. It: - Calls base.LateInitialize(...).
- Obtains the PrefabSystem from the entityManager.World to resolve m_Category into an Entity (or Entity.Null if none).
- Writes UIStatisticsGroupData to the entity with fields: m_Category (entity), m_Color, m_UnitType, m_Stacked. This step binds the prefab settings into the ECS component used at runtime by the UI systems.
Usage Example
// Example of how this prefab sets component data during LateInitialize,
// and how you might read the resulting component from an EntityManager.
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// After this point the entity has UIStatisticsGroupData populated.
var data = entityManager.GetComponentData<UIStatisticsGroupData>(entity);
Debug.Log($"Stats group color: {data.m_Color}, stacked: {data.m_Stacked}");
}