Skip to content

Game.Net.NodeLane

Assembly: Assembly-CSharp
Namespace: Game.Net

Type: public struct

Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents per-lane data attached to a node for networking/serialization and ECS queries. The primary data is a float2 m_WidthOffset (lane lateral offsets), plus two byte counters for shared-lane information at the start and end of the node. The struct implements custom compact serialization logic to minimize save size by only writing non-zero components of the width offset when possible.


Fields

  • public Unity.Mathematics.float2 m_WidthOffset
    Holds the lateral offset of the lane (X and Y components). Used to store small per-lane positional offsets relative to the base lane geometry. Serialization is optimized to avoid writing zero components.

  • public byte m_SharedStartCount
    Count of lanes that are "shared" at the start of the node. Typically used to track merging/splitting lanes or lanes that share the same start geometry.

  • public byte m_SharedEndCount
    Count of lanes that are "shared" at the end of the node. Typically used to track merging/splitting lanes or lanes that share the same end geometry.

Properties

  • None.

Constructors

  • public NodeLane()
    Implicit default constructor (value-type). Fields default to zero: m_WidthOffset = float2(0,0), m_SharedStartCount = 0, m_SharedEndCount = 0.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the NodeLane to the provided writer. Uses a compact encoding for m_WidthOffset:
  • Writes a single byte tag:
    • 0: both components zero
    • 1: only X is non-zero (then writes X as float)
    • 2: only Y is non-zero (then writes Y as float)
    • 3: both X and Y are non-zero (then writes X and Y as floats)
  • This avoids writing unnecessary zeros to reduce save size.
  • Note: The method writes only the width offset; shared counts are not written here (they may be stored elsewhere or defaulted).

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the NodeLane from the provided reader. Behavior depends on reader context version:

  • If reader.context.version >= Version.saveOptimizations:
    • Reads a single byte bitmask. Bit 0 (value & 1) indicates X present; Bit 1 (value & 2) indicates Y present.
    • Reads only the present components into m_WidthOffset.x / m_WidthOffset.y.
    • This mirrors the compact encoding used in Serialize.
  • Else (older save versions):
    • Reads the entire float2 m_WidthOffset directly from the reader (no compact encoding).
  • The method therefore supports backward compatibility with older save formats.

Usage Example

// Example: creating a NodeLane, setting offsets and serializing/deserializing
NodeLane lane = new NodeLane();
lane.m_WidthOffset = new float2(0.5f, 0f); // only X offset
lane.m_SharedStartCount = 1;
lane.m_SharedEndCount = 0;

// Serializing with an IWriter implementation
writer.WriteContext(someContext); // context must contain version info used by Deserialize
lane.Serialize(writer);

// Deserializing with an IReader implementation
NodeLane readLane = new NodeLane();
readLane.Deserialize(reader);
// readLane.m_WidthOffset now contains the same offsets that were written (respecting save version)

{{ Additional notes - This struct is designed for use in Unity's ECS (IComponentData) and can be used as a query parameter (IQueryTypeParameter) for systems operating on node-lane data. - The compact serialization helps reduce save file size by avoiding writing default/zero offset values. - The code does not explicitly serialize m_SharedStartCount / m_SharedEndCount in the shown methods; verify where those counts are stored/serialized in the broader save logic. }}