Game.Prefabs.TriggerCondition
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
TriggerCondition is a Unity component used by trigger prefabs to carry an array of TriggerConditionData entries that are transferred into an entity's DynamicBuffer at initialization time. The component is serialized (m_Conditions) so designers can populate conditions in the Inspector. When present on a prefab it causes the TriggerConditionData component to be added to the prefab's entity so the data can be buffered and consumed by ECS systems at runtime. The class is exposed in the Component menu under "Triggers/" and is intended to be used with TriggerPrefab and StatisticTriggerPrefab.
Fields
public TriggerConditionData[] m_Conditions
Serialized array of condition data. Populated in the Inspector or by code and later copied into the entity's DynamicBufferduring LateInitialize. If null or empty, no TriggerConditionData component is added to the prefab/entity.
Properties
- (none)
Constructors
public TriggerCondition()
Implicit default constructor. No special construction logic is defined in the source; initialization of runtime data happens in LateInitialize.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Checks whether m_Conditions is non-null and non-empty; if so, adds ComponentType.ReadWrite() to the supplied components set. This informs the prefab-to-entity conversion that a TriggerConditionData buffer component is required for entities instantiated from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. This class does not add any archetype-level components at this stage. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called after the entity has been created for the prefab. If m_Conditions contains entries, obtains the DynamicBufferfor the entity and appends each TriggerConditionData from the serialized array into the buffer. This transfers the serialized condition definitions into runtime ECS data.
Usage Example
// Populate the buffer for an existing entity (typically executed inside LateInitialize)
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
if (m_Conditions != null && m_Conditions.Length != 0)
{
var buffer = entityManager.GetBuffer<TriggerConditionData>(entity);
for (int i = 0; i < m_Conditions.Length; i++)
{
buffer.Add(m_Conditions[i]);
}
}
}
// Alternatively, add a single condition at runtime to an entity's buffer:
var buffer = entityManager.GetBuffer<TriggerConditionData>(entity);
buffer.Add(new TriggerConditionData {
// set fields of TriggerConditionData here
});
Notes: - Ensure the prefab includes a TriggerConditionData buffer component (GetPrefabComponents will add it automatically when m_Conditions is set). - TriggerConditionData is expected to be a struct suitable for use in a DynamicBuffer (BufferElementData-like). Confirm its layout when creating/modifying entries.