Skip to content

Game.Net.LaneObject

Assembly:
Game (assembly where the source file resides)

Namespace:
Game.Net

Type:
struct

Base:
IBufferElementData, IEquatable, IComparable, IEmptySerializable

Summary:
Represents a lane-related buffer element used by the game's ECS (Unity Entities) to associate an Entity with a position along a lane curve. This struct is intended to be stored in a DynamicBuffer on an entity. It carries a reference to another Entity (m_LaneObject) and a 2D curve position (m_CurvePosition). Equality is determined by the referenced entity only, while ordering is based on the x component of the curve position.


Fields

  • public Unity.Entities.Entity m_LaneObject
    Holds the Entity reference for the lane object. This field is used for identity and equality comparisons.

  • public Unity.Mathematics.float2 m_CurvePosition
    Stores the position on the lane curve as a float2. The x component is used for ordering (CompareTo), while the full float2 is included in the hash calculation.

Properties

  • None
    This struct exposes no C# properties; it uses public fields suitable for use as a buffer element in Unity's ECS.

Constructors

  • public LaneObject(Unity.Entities.Entity laneObject)
    Initializes a LaneObject with the provided Entity and sets m_CurvePosition to float2.zero (default).

  • public LaneObject(Unity.Entities.Entity laneObject, Unity.Mathematics.float2 curvePosition)
    Initializes a LaneObject with the provided Entity and curve position.

Methods

  • public bool Equals(LaneObject other)
    Returns true if this.m_LaneObject equals other.m_LaneObject. Note: m_CurvePosition is not considered for equality. As a result, two LaneObject instances that reference the same Entity are considered equal even if their curve positions differ.

  • public int CompareTo(LaneObject other)
    Compares this instance to another LaneObject by the x component of m_CurvePosition. Internally uses math.sign(m_CurvePosition.x - other.m_CurvePosition.x) cast to int, which results in -1, 0 or 1 depending on the relative ordering of the x values. This is suitable for sorting by curve position along the lane's primary axis (x).

  • public override int GetHashCode()
    Produces a combined hash code using m_LaneObject.GetHashCode() and m_CurvePosition.GetHashCode(). This includes both fields so the hash distinguishes different curve positions even though Equals only compares the Entity.

Additional notes: - The struct is annotated with [InternalBufferCapacity(0)], indicating no inlined storage for the buffer element; buffer elements will be allocated in the dynamic buffer storage. - Implements IEmptySerializable (from Colossal.Serialization.Entities), which indicates support for the game's custom/empty serialization; no explicit serialization methods are present in this struct itself.

Usage Example

// Example showing how to add and use a DynamicBuffer<LaneObject> on an entity in a system:
using Unity.Entities;
using Unity.Mathematics;
using Game.Net;

public partial class ExampleSystem : SystemBase
{
    protected override void OnCreate()
    {
        base.OnCreate();
        // Create an entity with a buffer (pseudo-code; create archetype as needed)
    }

    protected override void OnUpdate()
    {
        Entities
          .WithName("AddLaneObjectToEntities")
          .ForEach((Entity e, ref DynamicBuffer<LaneObject> laneBuffer) =>
          {
              // Create a LaneObject pointing to some other entity (laneEntity)
              Entity laneEntity = /* obtain or create the lane object entity */;
              var laneObj = new LaneObject(laneEntity, new float2(12.5f, 0f));

              // Add to buffer
              laneBuffer.Add(laneObj);

              // Example: sort buffer by curve position x
              laneBuffer.Sort((a, b) => a.CompareTo(b));
          }).Schedule();
    }
}