Skip to content

Game.Prefabs.CarLaneData

Assembly: Game
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents lane prefab references and lane constraints used by the game's ECS systems. Stores two prefab Entity references (for non-track and non-bus lane prefabs) and two enum-based constraints: RoadTypes (which road categories this lane applies to) and SizeClass (maximum vehicle size allowed on this lane). Implements custom binary serialization for the enum fields (but not for the Entity prefab references), and is intended for use as a component/query parameter in Unity.Entities-based systems.


Fields

  • public Entity m_NotTrackLanePrefab
    Reference to the prefab Entity used for lanes that are not track-based (e.g., car/road lanes without rail tracks). This field is not serialized by this struct's Serialize method.

  • public Entity m_NotBusLanePrefab
    Reference to the prefab Entity used for lanes that are not bus-specific (name implies a prefab for non-bus lane variant). This field is not serialized by this struct's Serialize method.

  • public RoadTypes m_RoadTypes
    Bitmask/enum indicating which road types this lane supports. Serialized as a single byte in Serialize/Deserialize.

  • public SizeClass m_MaxSize
    Enum indicating the maximum vehicle size class permitted on this lane. Serialized as a single byte in Serialize/Deserialize.

Properties

  • This struct exposes no public properties.

Constructors

  • public CarLaneData()
    Default parameterless struct constructor. Entities default to Entity.Null and enum fields default to their zero values. Typical usage is to set fields explicitly after construction.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the compact binary representation of the enum fields to the provided writer:
  • Writes m_RoadTypes as a single byte: writer.Write((byte)m_RoadTypes)
  • Writes m_MaxSize as a single byte: writer.Write((byte)m_MaxSize) Note: Entity prefab references (m_NotTrackLanePrefab, m_NotBusLanePrefab) are not written by this method — prefab references are expected to be handled separately by the engine's prefab/entity serialization logic.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads two bytes from the reader and assigns them to the enum fields:

  • Reads a byte and casts to RoadTypes for m_RoadTypes
  • Reads a byte and casts to SizeClass for m_MaxSize The Entity prefab fields remain untouched; they must be provided/linked elsewhere when reconstructing prefabs/components.

Implementation notes and gotchas: - Both enums are serialized as bytes. If RoadTypes or SizeClass expand to require values outside the 0–255 range, serialization will truncate and cause data corruption — ensure enum values fit in a byte. - Prefab Entity references are not serialized here; missing linkage may result if prefab wiring is expected solely from these fields.

Usage Example

// Example: creating and initializing a CarLaneData instance
CarLaneData laneData = new CarLaneData
{
    m_NotTrackLanePrefab = somePrefabEntity,
    m_NotBusLanePrefab = someOtherPrefabEntity,
    m_RoadTypes = RoadTypes.Road | RoadTypes.Highway,
    m_MaxSize = SizeClass.Large
};

// Serialize enums (requires an IWriter implementation)
IWriter writer = ...; // provided by the engine's serialization system
laneData.Serialize(writer);

// Deserialize (requires an IReader implementation)
IReader reader = ...;
CarLaneData loaded = new CarLaneData();
loaded.Deserialize(reader);
// Note: loaded.m_NotTrackLanePrefab and loaded.m_NotBusLanePrefab must be set
// by the prefab/entity system after deserialization if required.