Game.Prefabs.TrackPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: NetGeometryPrefab
Summary:
Represents a net prefab for rail-type networks (train, tram, subway). Provides configurable track type and speed limit, contributes required ECS component types for prefab and archetype creation, and exposes mod tags derived from the track type. This prefab is used to register/define rail network prefabs so the simulation can add appropriate components (TrackData, Track-specific markers like TrainTrack/TramTrack/SubwayTrack) depending on the archetype (Edge, Node, or Net composition).
Fields
-
public TrackTypes m_TrackType = TrackTypes.Train
Defines which track type(s) this prefab represents (Train, Tram, Subway, or combinations). Used to add specific marker components (TrainTrack/TramTrack/SubwayTrack) and to generate modTags that include the track type. -
public float m_SpeedLimit = 100f
Default speed limit for the track prefab (units as used by the simulation). Can be tuned per prefab to influence vehicle speed on this net.
Properties
public override IEnumerable<string> modTags { get; }
Returns the prefab's mod tags. Yields the base mod tags from the parent, then appends tags derived from the enum flags in m_TrackType (using ModTags.GetEnumFlagTags) with the suffix "Track" (e.g., "TrainTrack", "TramTrack"). Useful for category/tag based filtering in mod tools or content browsers.
Constructors
public TrackPrefab()
Default constructor. Field initializers set m_TrackType to TrackTypes.Train and m_SpeedLimit to 100f. No additional initialization logic in the class.
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs)
Calls the base implementation. Placeholder for adding additional prefab dependencies if required. As implemented, it does not add extra dependencies beyond the base class. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types required by the prefab at creation time. Calls base then adds ComponentType.ReadWrite() so entities created from this prefab include TrackData. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds archetype-level component types depending on which components are already present in the given set: - If Edge is present: adds UpdateFrame, EdgeColor, and track-type-specific marker via AddTrackType.
- Else if Node is present: adds UpdateFrame, NodeColor, and track-type-specific marker via AddTrackType.
-
Else if NetCompositionData is present: adds TrackComposition. This method configures different archetypes (edge entities, node entities, composition entities) with the components the simulation systems expect.
-
private void AddTrackType(HashSet<ComponentType> components)
Adds a marker component corresponding to m_TrackType: - TrackTypes.Train -> adds ComponentType.ReadWrite
() - TrackTypes.Tram -> adds ComponentType.ReadWrite
() - TrackTypes.Subway -> adds ComponentType.ReadWrite
() - TrackTypes.Train | TrackTypes.Tram -> (no action in current implementation) Note: The switch handles simple enum values; combined flags may not add a specific component (see Train|Tram case) — this likely indicates either shared behavior or an intentional no-op for combined types.
Usage Example
// Create and configure a TrackPrefab instance in code (note: prefabs are commonly created/edited as assets)
var prefab = new Game.Prefabs.TrackPrefab();
prefab.m_TrackType = TrackTypes.Tram;
prefab.m_SpeedLimit = 80f;
// Query the mod tags
foreach (var tag in prefab.modTags)
{
Debug.Log(tag); // includes base tags and "TramTrack"
}
// Prepare component sets and see what components the prefab declares
var prefabComponents = new HashSet<ComponentType>();
prefab.GetPrefabComponents(prefabComponents); // will include TrackData
var archetypeComponents = new HashSet<ComponentType>();
// Simulate an edge archetype already containing Edge()
archetypeComponents.Add(ComponentType.ReadWrite<Edge>());
prefab.GetArchetypeComponents(archetypeComponents);
// archetypeComponents will now include UpdateFrame, EdgeColor and TramTrack (for m_TrackType == Tram)
{{ Notes/Tips }} - m_TrackType is an enum and can potentially be a flags enum — be careful when using combined flags because AddTrackType currently has an empty branch for Train|Tram. - Track prefabs are typically authored as assets in the game editor; modifying them at runtime requires understanding how the game's prefab registration works. - The components added (TrackData, TrainTrack/TramTrack/SubwayTrack, UpdateFrame, EdgeColor/NodeColor, TrackComposition) are what simulation systems expect to find on edge/node/composition entities for rail networks.