Skip to content

Game.Prefabs.WorkRoutePrefab

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: class

Base: RoutePrefab

Summary:
Prefab class that defines configuration and required ECS components for "work" routes used by the routing/vehicle systems. Exposes editable prefab fields for route road type and size class. When initialized it writes RouteConnectionData and WorkRouteData components onto the entity so the runtime route systems know the connection types, track/road types and size class used by this route prefab.


Fields

  • public RoadTypes m_RouteRoadType = RoadTypes.Car
    Specifies the main road type used by the route. Default is RoadTypes.Car. This value is written into the RouteConnectionData.m_RouteRoadType during LateInitialize.

  • public SizeClass m_SizeClass = SizeClass.Large
    Specifies the size class for the route (e.g., Small, Medium, Large). Default is SizeClass.Large. This value is written into WorkRouteData.m_SizeClass and RouteConnectionData.m_RouteSizeClass during LateInitialize.

Properties

  • None declared on this prefab. (No public properties in this class; behaviour is provided via overridden methods and public fields.)

Constructors

  • public WorkRoutePrefab()
    Default parameterless constructor (compiler-provided). The class relies on Unity/Editor to populate public fields on the prefab instance.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Called to collect other prefab dependencies. This override currently calls the base implementation and does not add additional dependencies.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds required ECS component types to the prefab archetype. This implementation calls the base then adds:

  • RouteConnectionData (ReadWrite)
  • WorkRouteData (ReadWrite)
  • PlaceableInfoviewItem (ReadWrite)

These components are required so that the entity created from the prefab contains route connection configuration, work-route specific data and an infoview item entry.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds additional archetype components depending on which core components are present in the target archetype:
  • If Route exists -> adds WorkRoute
  • Else if Waypoint exists -> adds AccessLane and RouteLane
  • Else if Game.Routes.Segment exists -> adds PathTargets, RouteInfo, PathElement, PathInformation

This conditional logic ensures the prefab contributes the correct low-level components depending on whether it's used as a route, waypoint, or segment archetype.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called after the entity is created from the prefab to write initial component data. This implementation:
  • Calls base.LateInitialize(...)
  • Sets RouteConnectionData on the entity with values:
    • m_AccessConnectionType = RouteConnectionType.Pedestrian
    • m_RouteConnectionType = RouteConnectionType.Road
    • m_AccessTrackType = TrackTypes.None
    • m_RouteTrackType = TrackTypes.None
    • m_AccessRoadType = RoadTypes.None
    • m_RouteRoadType = this.m_RouteRoadType (from prefab field)
    • m_RouteSizeClass = this.m_SizeClass (from prefab field)
    • m_StartLaneOffset = 0f
    • m_EndMargin = 0f
  • Sets WorkRouteData on the entity with:
    • m_SizeClass = this.m_SizeClass

LateInitialize is the point where prefab field values are translated into ECS component data used by the routing/pathfinding systems.

Usage Example

using Unity.Entities;
using UnityEngine;
using Unity.Scripting;

[Preserve]
public class MyCustomWorkRoutePrefab : Game.Prefabs.WorkRoutePrefab
{
    [Preserve]
    public override void LateInitialize(EntityManager entityManager, Entity entity)
    {
        base.LateInitialize(entityManager, entity);

        // Example: read back the data we just wrote
        var routeConn = entityManager.GetComponentData<Game.Routes.RouteConnectionData>(entity);
        var workData = entityManager.GetComponentData<Game.Prefabs.WorkRouteData>(entity);
        Debug.Log($"Route road type: {routeConn.m_RouteRoadType}, route size: {routeConn.m_RouteSizeClass}, work size: {workData.m_SizeClass}");
    }
}