Skip to content

Game.Objects.BlockedLane

Assembly: Assembly-CSharp (inferred)
Namespace: Game.Objects

Type: struct

Base: System.ValueType, Unity.Entities.IBufferElementData, System.IEquatable, Colossal.Serialization.Entities.ISerializable

Summary:
Represents a blocked lane entry stored in an ECS dynamic buffer. Contains a reference to the lane entity and a curve position (float2) along that lane. The struct is suitable for buffering multiple blocked lanes on an entity (e.g., a road segment or intersection). The attribute [InternalBufferCapacity(0)] indicates no built-in inline capacity for the buffer element; elements will be stored out-of-line.


Fields

  • public Entity m_Lane
    Represents the Entity identifying the lane that is blocked. Equality and GetHashCode are based solely on this field.

  • public float2 m_CurvePosition
    A float2 giving the curve position along the lane where the block occurs (likely local/curve coordinates used by lane geometry or pathing).

Properties

  • This type defines no properties.

Constructors

  • public BlockedLane(Entity lane, float2 curvePosition)
    Creates a new BlockedLane with the provided lane entity and curve position. Note that as a struct it also has the implicit default constructor which will default m_Lane to Entity.Null and m_CurvePosition to float2(0,0).

Methods

  • public bool Equals(BlockedLane other)
    Implements IEquatable. Returns true if this.m_Lane equals other.m_Lane. The comparison ignores m_CurvePosition — two BlockedLane instances are considered equal if they reference the same lane entity.

  • public override int GetHashCode()
    Returns the hash code of m_Lane. Consistent with Equals, the hash does not incorporate m_CurvePosition.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the instance by writing the lane Entity followed by the curve position float2. This is used by the mod/game serialization system to persist buffer contents.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the instance by reading into m_Lane and m_CurvePosition (reads by ref). Matches the order used in Serialize.

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Game.Objects;

// Assume 'entityManager' is available and 'ownerEntity' has a DynamicBuffer<BlockedLane>
Entity laneEntity = /* obtain lane entity */;
float2 curvePos = new float2(0.25f, 0.5f);

var buffer = entityManager.GetBuffer<BlockedLane>(ownerEntity);
buffer.Add(new BlockedLane(laneEntity, curvePos));

// Check if a lane is already blocked (equality checks only the lane Entity)
BlockedLane probe = new BlockedLane(laneEntity, float2.zero);
bool exists = false;
for (int i = 0; i < buffer.Length; i++)
{
    if (buffer[i].Equals(probe))
    {
        exists = true;
        break;
    }
}

// Serialization is handled by the game's writer/reader via the Serialize/Deserialize methods.
// You don't normally call these directly unless implementing custom persistence logic.