Game.Prefabs.StatisticTriggerData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary:
A simple ECS component that describes a statistic-based trigger attached to a prefab/entity. Used by the game's systems to monitor a statistic (or statistic-derived value) and evaluate conditions (triggers) over a time window. This struct only holds configuration/state data — the systems that query IComponentData and IQueryTypeParameter will interpret the fields to compute whether a trigger condition has been met.
Fields
-
public StatisticTriggerType m_Type
Type of trigger/statistic to monitor. This typically encodes what kind of statistic or comparison is to be performed (for example rate, absolute value, threshold comparison, etc.). Refer to the StatisticTriggerType enum in game code/mod API for exact meanings. -
public Entity m_StatisticEntity
Entity reference that owns or provides the statistic to monitor. Often this points to a prefab or an instantiated entity that exposes a statistic component the trigger will sample. -
public int m_StatisticParameter
Index or ID of a parameter within the statistic source to sample. Many statistic providers expose multiple values (parameters); this selects which one to use for trigger evaluation. -
public Entity m_NormalizeWithPrefab
Optional entity/prefab reference used to normalize the sampled statistic (for example, per-capita normalization). If not used, this will typically be Entity.Null. -
public int m_NormalizeWithParameter
Index/ID of a parameter on the normalization prefab/entity to use as the divisor for normalization. Paired with m_NormalizeWithPrefab. -
public int m_TimeFrame
Window length over which the statistic is evaluated (sample window). The unit depends on the simulation/system reading it (often simulation ticks, frames, or seconds as interpreted by the statistic system). -
public int m_MinSamples
Minimum number of samples required before the trigger is considered valid. Prevents triggering on too few samples or transient data.
Properties
- This struct exposes no C# properties. All data is stored in public fields (POD style) for use by ECS systems.
Constructors
public StatisticTriggerData()
(implicit/default)
Default, auto-generated parameterless constructor. All fields default to zero/null (e.g., m_Type default value, m_StatisticEntity == Entity.Null, ints == 0).
Methods
- None. This is a plain data container (component) with no behavior methods. Behavior is implemented by systems that read instances of this component.
Usage Example
// Example: attach a StatisticTriggerData to an entity/prefab in a system or during prefab setup.
using Unity.Entities;
using Game.Prefabs; // for StatisticTriggerData and StatisticTriggerType
// Create and populate the component data
var trigger = new StatisticTriggerData
{
m_Type = StatisticTriggerType.Average, // example enum value
m_StatisticEntity = someStatisticEntity, // entity that exposes the statistic
m_StatisticParameter = 0, // first parameter of the statistic
m_NormalizeWithPrefab = normalizationEntity, // optional normalization entity (or Entity.Null)
m_NormalizeWithParameter = 1, // parameter index for normalization
m_TimeFrame = 600, // example timeframe (units depend on system)
m_MinSamples = 5 // wait for at least 5 samples before evaluating
};
// Add to an entity (EntityManager or during authoring)
entityManager.AddComponentData(targetEntity, trigger);
// Systems reading StatisticTriggerData will sample the referenced statistic entity,
// optionally normalize it, and evaluate the configured trigger type over the time frame.
Notes: - Units and semantics for m_TimeFrame and m_MinSamples depend on the consuming systems in the game's code; consult the corresponding statistic/trigger systems for exact interpretation. - m_StatisticEntity and m_NormalizeWithPrefab are Entity handles — ensure referenced entities exist and expose the expected statistic parameters.