Skip to content

Game.Prefabs.TriggerLimit

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
TriggerLimit is a Unity component used on prefab GameObjects to provide a trigger rate limit as an ECS component. It exposes m_IntervalSeconds (in seconds) in the inspector and, during prefab conversion/initialization, converts that interval into a frame-based interval (assuming 60 frames per second) and writes it into a TriggerLimitData component on the created Entity. The component is placed into Unity's component menu under "Triggers/" and is associated with TriggerPrefab.


Fields

  • public float m_IntervalSeconds
    Seconds between trigger activations as configured on the prefab. This value is converted to a frame interval (m_FrameInterval) during Initialize by multiplying by 60 and rounding to the nearest integer.

Properties

  • (none)

Constructors

  • public TriggerLimit()
    Implicit default constructor (not defined explicitly in source).

Methods

  • public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    Intentionally empty in this implementation. This method can be used to declare components necessary for an entity archetype, but TriggerLimit does not add archetype components here.

  • public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    Adds the TriggerLimitData component type to the prefab's component set so that prefab conversion/initialization will include a TriggerLimitData component on the resulting Entity: components.Add(ComponentType.ReadWrite());

  • public override void Initialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
    Called during prefab conversion/initialization. Calls base.Initialize and then writes a TriggerLimitData instance to the entity. The m_FrameInterval field of TriggerLimitData is computed from m_IntervalSeconds by rounding Mathf.RoundToInt(m_IntervalSeconds * 60f) and casting to uint.

Usage Example

[ComponentMenu("Triggers/", new Type[] { typeof(TriggerPrefab) })]
public class TriggerLimit : ComponentBase
{
    // Set in inspector (seconds)
    public float m_IntervalSeconds;

    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        components.Add(ComponentType.ReadWrite<TriggerLimitData>());
    }

    public override void Initialize(EntityManager entityManager, Entity entity)
    {
        base.Initialize(entityManager, entity);
        // Convert seconds -> frames (assumes 60 FPS) and store as uint
        entityManager.SetComponentData(entity, new TriggerLimitData
        {
            m_FrameInterval = (uint)Mathf.RoundToInt(m_IntervalSeconds * 60f)
        });
    }
}

Notes: - TriggerLimitData is expected to be an ECS component/struct with at least a uint m_FrameInterval field. - The conversion uses 60 frames per second as the baseline. Adjust if your simulation uses a different frame rate.