Game.TrafficConfigurationPrefab
Assembly:
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Prefab that groups notification icon prefabs used by the traffic system. This prefab holds references to NotificationIconPrefab instances for different traffic-related events (bottleneck, dead end, various connection types) and is responsible for registering those references into the ECS world by writing a TrafficConfigurationData component during LateInitialize. Use this prefab to centralize which notification icons the traffic systems should show for specific events.
Fields
-
public NotificationIconPrefab m_BottleneckNotification
Reference to the notification icon prefab used for traffic bottlenecks. -
public NotificationIconPrefab m_DeadEndNotification
Reference to the notification icon prefab used for dead-end road notifications. -
public NotificationIconPrefab m_RoadConnectionNotification
Reference to the notification icon prefab used when a road connection is highlighted. -
public NotificationIconPrefab m_TrackConnectionNotification
Reference to the notification icon prefab used for track (rail) connections. -
public NotificationIconPrefab m_CarConnectionNotification
Reference to the notification icon prefab used for car-specific connections. -
public NotificationIconPrefab m_ShipConnectionNotification
Reference to the notification icon prefab used for ship/sea connections. -
public NotificationIconPrefab m_TrainConnectionNotification
Reference to the notification icon prefab used for train connections. -
public NotificationIconPrefab m_PedestrianConnectionNotification
Reference to the notification icon prefab used for pedestrian connections.
(Each field should be assigned in the prefab asset — null or missing assignments will result in invalid/empty entity references when the TrafficConfigurationData is written.)
Properties
- (No public properties declared on this type — the prefab exposes its data via public fields and writes a TrafficConfigurationData component during initialization.)
Constructors
public TrafficConfigurationPrefab()
Default constructor (no custom initialization). The class relies on the prefab asset data and overrides of PrefabBase lifecycle methods for runtime behavior.
Methods
-
public override void GetDependencies(System.Collections.Generic.List<PrefabBase> prefabs)
Adds all referenced NotificationIconPrefab instances to the provided dependency list. This ensures those prefabs are included when resolving and loading prefab dependencies. Implementation calls base.GetDependencies(prefabs) then adds each m_XXXNotification field to the list. -
public override void GetPrefabComponents(System.Collections.Generic.HashSet<ComponentType> components)
Registers the ECS component types that this prefab will produce. Specifically, it adds ComponentType.ReadWrite() to the set so the prefab system knows the entity will have TrafficConfigurationData. -
public override void LateInitialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Called late in the prefab-to-entity conversion process. This method: - Obtains the PrefabSystem from the world (entityManager.World.GetOrCreateSystemManaged
()). - Resolves each NotificationIconPrefab field to an Entity using PrefabSystem.GetEntity(prefab).
- Writes a TrafficConfigurationData struct into the target entity via entityManager.SetComponentData, populating its fields with the resolved entity references. This is the step that converts the editor-assigned prefab references into runtime entity references used by traffic systems.
Usage Example
// Example: reading the configured notification entities at runtime
var prefabSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<PrefabSystem>();
Entity trafficConfigEntity = prefabSystem.GetEntity(myTrafficConfigurationPrefab); // if you have the prefab reference
TrafficConfigurationData data = entityManager.GetComponentData<TrafficConfigurationData>(trafficConfigEntity);
// access the bottleneck notification entity
Entity bottleneckNotificationEntity = data.m_BottleneckNotification;
Notes and tips: - Ensure each NotificationIconPrefab field is assigned in the prefab asset in the editor; LateInitialize simply resolves whatever references are present. - The TrafficConfigurationData component stores Entity references — consumers of this data should query those entities to spawn/show the corresponding notification icons. - Because this prefab writes a component of type TrafficConfigurationData, systems that depend on it should declare the component in their queries or register it in their prefab/component dependency lists as needed.