Game.Prefabs.RouteInitializeSystem
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: GameSystemBase
Summary:
RouteInitializeSystem is a compiler-generated ECS system that runs when prefabs are created. It initializes route-related runtime components (RouteData and ObjectGeometryData) based on the corresponding prefab (RoutePrefab) and the presence of related marker components (TransportLineData, WorkRouteData, TransportStopData, MailBoxData, WorkStopData). The system:
- Queries prefabs that are newly created (Created + PrefabData) and that contain any of the route/stop markers.
- For entities with RouteData, it looks up the RoutePrefab and initializes RouteData fields such as snap distance, type (transport/work), color, width and segment length.
- For entities representing stops/mailboxes/workstops, it updates ObjectGeometryData flags to clear Overridable and Brushable so these objects are not overridden by brush tools.
- Uses ComponentTypeHandle handles (cached in a nested TypeHandle) and iterates archetype chunks for performant bulk updates.
- Calls CompleteDependency() before modifying component data to ensure job dependencies are resolved.
Fields
-
private struct TypeHandle
TypeHandle is a nested struct that caches ComponentTypeHandleinstances used by the system (both read-only and read/write handles). It exposes an __AssignHandles(ref SystemState) helper to fetch the component handles from a SystemState. The cached handles include PrefabData (RO), RouteData (RW), TransportLineData (RO), WorkRouteData (RO), TransportStopData (RO), MailBoxData (RO), WorkStopData (RO), and ObjectGeometryData (RW). -
private PrefabSystem m_PrefabSystem
Reference to the PrefabSystem used to resolve the concrete RoutePrefab (RoutePrefab) instances from PrefabData. Used during OnUpdate to read prefab defaults (color, width, segment length). -
private EntityQuery m_PrefabQuery
An EntityQuery set up in OnCreate that matches entities with Created and PrefabData, and any of RouteData, TransportStopData, MailBoxData, or WorkStopData. The system requires this query for update. -
private TypeHandle __TypeHandle
Instance of the nested TypeHandle struct used to store ComponentTypeHandleinstances for chunk access. Populated in OnCreateForCompiler via __AssignHandles.
Properties
- None
Constructors
public RouteInitializeSystem()
Default parameterless constructor. Marked with [Preserve] on the class and constructor to avoid stripping; the system is compiler-generated.
Methods
-
protected override void OnCreate()
Initializes the system: acquires the PrefabSystem (World.GetOrCreateSystemManaged()), builds m_PrefabQuery that requires Created + PrefabData and any of RouteData/TransportStopData/MailBoxData/WorkStopData, and calls RequireForUpdate(m_PrefabQuery). Also prepared for compiler-managed handle assignment via OnCreateForCompiler. -
protected override void OnUpdate()
Main update logic: - Converts m_PrefabQuery to an array of ArchetypeChunk (TempJob) and obtains component type handles via InternalCompilerInterface.GetComponentTypeHandle using the cached __TypeHandle entries.
- Calls CompleteDependency() to ensure no outstanding jobs conflict with immediate writes.
- Iterates each archetype chunk:
- If the chunk has RouteData: for each entry, obtains the RoutePrefab from m_PrefabSystem using the PrefabData, then sets RouteData fields:
- m_SnapDistance = max(8f (for lines) or 0f, prefab.m_Width)
- m_Type = RouteType.TransportLine or RouteType.WorkRoute depending on presence of TransportLineData or WorkRouteData
- m_Color = prefab.m_Color
- m_Width = prefab.m_Width
- m_SegmentLength = prefab.m_SegmentLength
- If the chunk has TransportStopData or MailBoxData or WorkStopData: for each ObjectGeometryData in the chunk, clears the GeometryFlags.Overridable and GeometryFlags.Brushable bits (value.m_Flags &= ~(Overridable | Brushable)).
-
Disposes the native archetype chunk array.
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper stub used at OnCreateForCompiler time; in this class it builds and disposes an EntityQueryBuilder(Allocator.Temp) (no custom queries beyond m_PrefabQuery built in OnCreate). -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to populate the cached component handles for chunk access. -
private void TypeHandle.__AssignHandles(ref SystemState state)
(Defined inside nested TypeHandle) Populates the ComponentTypeHandlefields by calling state.GetComponentTypeHandle (isReadOnly) for the various components required by the system.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire PrefabSystem and set up query (the real system does more setup)
m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
m_PrefabQuery = GetEntityQuery(new EntityQueryDesc {
All = new ComponentType[] {
ComponentType.ReadOnly<Created>(),
ComponentType.ReadOnly<PrefabData>()
},
Any = new ComponentType[] {
ComponentType.ReadOnly<RouteData>(),
ComponentType.ReadOnly<TransportStopData>(),
ComponentType.ReadOnly<MailBoxData>(),
ComponentType.ReadOnly<WorkStopData>()
}
});
RequireForUpdate(m_PrefabQuery);
}
Additional notes: - The system is [CompilerGenerated] and uses low-level ECS patterns (ComponentTypeHandle, ArchetypeChunk) for performance. - It performs immediate writes to component data after CompleteDependency(), so it runs synchronously with respect to job dependencies. - The snap distance default of 8f is used for transport lines and work routes in addition to the prefab width.