Skip to content

Game.Prefabs.TrafficSignObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
TrafficSignObject is a prefab/component authoring class used to configure traffic sign entities for the ECS world. It exposes an array of TrafficSignType entries and a speed limit. During LateInitialize it composes a TrafficSignData component (setting a type bitmask and the speed limit) and writes it to the entity. This ensures spawned entities have the correct TrafficSignData for runtime systems to use. TrafficSignData is expected to contain at least a uint m_TypeMask and an int m_SpeedLimit and a static GetTypeMask(TrafficSignType) helper.


Fields

  • public TrafficSignType[] m_SignTypes
    Array of sign types this prefab represents. Each entry contributes a bit to the TrafficSignData.m_TypeMask via TrafficSignData.GetTypeMask.

  • public int m_SpeedLimit
    Speed limit value that will be written into TrafficSignData.m_SpeedLimit during LateInitialize.

Properties

  • This type does not declare any public properties.

Constructors

  • public TrafficSignObject()
    Default constructor (implicitly provided). No special runtime construction logic is defined in the class source.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the required ECS component type to the prefab description. Implementation adds ComponentType.ReadWrite() so spawned entities will include TrafficSignData.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override. No additional archetype-level component constraints are added by this prefab class.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Initializes the TrafficSignData for the created entity:

  • Creates a TrafficSignData instance.
  • Initializes m_TypeMask to 0 and m_SpeedLimit from m_SpeedLimit field.
  • If m_SignTypes is set, iterates the array and ORs each TrafficSignData.GetTypeMask(type) into m_TypeMask.
  • Calls entityManager.SetComponentData(entity, componentData) to write the component to the entity.

Usage Example

// The prefab is typically configured in the editor (assigning m_SignTypes and m_SpeedLimit).
// At spawn time LateInitialize will run. The following shows the same logic as the class's LateInitialize.

public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);

    TrafficSignData componentData = default(TrafficSignData);
    componentData.m_TypeMask = 0u;
    componentData.m_SpeedLimit = m_SpeedLimit;

    if (m_SignTypes != null)
    {
        for (int i = 0; i < m_SignTypes.Length; i++)
        {
            componentData.m_TypeMask |= TrafficSignData.GetTypeMask(m_SignTypes[i]);
        }
    }

    entityManager.SetComponentData(entity, componentData);
}

{{ Notes - Ensure TrafficSignData and TrafficSignType definitions match expectations: GetTypeMask should return a mask bit for the given TrafficSignType. - GetPrefabComponents ensures the ECS entity will have a writable TrafficSignData component; other systems can then read that data to render or apply traffic behaviors. - GetArchetypeComponents being empty means the prefab does not force additional archetype components at creation time beyond those collected elsewhere. }}