Skip to content

Game.Prefabs.RouteConnectionData

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

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
RouteConnectionData is an ECS component/data container used by prefab and entity systems to describe how a route (vehicle/track/road) connects to another element. It records connection types for both the access side and the route side, the track and road types involved, route size class, and two positioning floats (start lane offset and end margin). The struct implements ISerializable to support binary serialization/deserialization (used by saving/loading, networking, and prefab serialization) and is intended to be attached to entities or stored on prefabs to control routing behavior.


Fields

  • public RouteConnectionType m_AccessConnectionType
    The connection type on the "access" side of the connection (e.g., how the accessing segment connects). Serialized as a single byte.

  • public RouteConnectionType m_RouteConnectionType
    The connection type on the "route" side of the connection. Serialized as a single byte.

  • public TrackTypes m_AccessTrackType
    The track type used by the access side. Serialized as a single byte.

  • public TrackTypes m_RouteTrackType
    The track type used by the route side. Serialized as a single byte.

  • public RoadTypes m_AccessRoadType
    The road type used by the access side. Serialized as a single byte.

  • public RoadTypes m_RouteRoadType
    The road type used by the route side. Serialized as a single byte.

  • public SizeClass m_RouteSizeClass
    Size class for the route (affects spacing/placement). Serialized as a single byte.

  • public float m_StartLaneOffset
    Floating-point offset applied at the start lane when placing the connection. Serialized as a 32-bit float.

  • public float m_EndMargin
    Floating-point margin applied at the end of the connection. Serialized as a 32-bit float.

Properties

  • This type exposes no properties. (All data is public fields; the struct implements interfaces but does not declare C# properties.)

Constructors

  • public RouteConnectionData()
    Implicit default constructor provided by C#. All fields are initialized to their default values (enum members with value 0, floats = 0f). No custom ctor is defined in the source.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data into the provided writer in a compact binary form. Enum fields are cast to byte and written in the following order: m_AccessConnectionType, m_RouteConnectionType, m_AccessTrackType, m_RouteTrackType, m_AccessRoadType, m_RouteRoadType, m_RouteSizeClass. Then the two floats m_StartLaneOffset and m_EndMargin are written. Note: enums are truncated/cast to a single byte; ensure enum values fit in 0..255.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads values in the same order they were written by Serialize. Bytes are read into temporary byte variables and cast back to the corresponding enum types. Floats are read into the m_StartLaneOffset and m_EndMargin fields. Keep read/write order identical to avoid deserialization errors.

Usage Example

// Example: creating and populating a RouteConnectionData instance,
// then serializing it with a hypothetical writer.

RouteConnectionData data = new RouteConnectionData {
    m_AccessConnectionType = RouteConnectionType.Junction,
    m_RouteConnectionType = RouteConnectionType.Platform,
    m_AccessTrackType = TrackTypes.Rail,
    m_RouteTrackType = TrackTypes.Rail,
    m_AccessRoadType = RoadTypes.None,
    m_RouteRoadType = RoadTypes.None,
    m_RouteSizeClass = SizeClass.Medium,
    m_StartLaneOffset = 0.25f,
    m_EndMargin = 0.15f
};

// Serialize
IWriter writer = /* obtain writer from serialization system */;
data.Serialize(writer);

// Deserialize (e.g., when loading)
IReader reader = /* obtain reader containing previously written data */;
RouteConnectionData loaded;
loaded.Deserialize(reader);

// The struct can also be added as an ECS component (IComponentData) to an Entity:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddComponentData(e, loaded);

Notes and caveats: - Serialization casts enums to bytes. Ensure custom enum values (if changed in mods) remain within byte range or adjust serialization accordingly. - The binary order is important — change both Serialize and Deserialize together if modifying layout. - As an IComponentData, this struct is suitable for use in Unity.Entities systems and entity archetypes; treat it as plain data (no managed references).