Skip to content

Game.Vehicles.LayoutElement

Assembly: Assembly-CSharp
Namespace: Game.Vehicles

Type: struct LayoutElement

Base: IBufferElementData, IEquatable, ISerializable

Summary:
A small buffer element used by the game's ECS to reference a vehicle entity in layout-related buffers. The struct stores a single Unity.Entities.Entity (m_Vehicle), implements equality and hash code based on that entity, and supports Colossal's binary serialization via ISerializable. The type is annotated with [InternalBufferCapacity(0)], indicating the default internal buffer capacity is 0 (no preallocated inline capacity).


Fields

  • public Unity.Entities.Entity m_Vehicle
    Holds the reference to the vehicle Entity for this layout element. This is the primary payload of the struct and is used for comparisons, hashing, and serialization.

Properties

  • This type defines no properties.

Constructors

  • public LayoutElement(Unity.Entities.Entity vehicle)
    Constructs a LayoutElement wrapping the provided Entity. Use this to create and add entries to an IBufferElementData buffer.

Methods

  • public bool Equals(LayoutElement other)
    Compares this LayoutElement with another by comparing their m_Vehicle fields (delegates to Entity.Equals).

  • public override int GetHashCode()
    Returns the hash code of the contained Entity (delegates to Entity.GetHashCode).

  • public void Serialize<TWriter>(TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
    Writes the contained Entity to the provided writer for binary serialization. This enables the buffer element to be serialized as part of save/load or networked state.

  • public void Deserialize<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
    Reads an Entity value from the provided reader and stores it in m_Vehicle. Complements Serialize for restoring state.

Usage Example

// Add a buffer of LayoutElement to an entity and append a vehicle entity reference
Entity layoutOwner = /* some entity that owns the layout buffer */;
Entity vehicleEntity = /* the vehicle entity to reference */;

var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var buffer = em.AddBuffer<Game.Vehicles.LayoutElement>(layoutOwner);
buffer.Add(new Game.Vehicles.LayoutElement(vehicleEntity));

// Iterate buffer entries
foreach (var elem in buffer)
{
    Entity v = elem.m_Vehicle;
    // use v (e.g., query components, schedule jobs, etc.)
}

Notes: - The [InternalBufferCapacity(0)] attribute means no inline storage is reserved on the owning entity; buffers will use heap storage immediately. This is typically chosen when buffer sizes are expected to vary or be large. - Serialization uses Colossal.Serialization.Entities writers/readers specialized for serializing Unity.Entities.Entity values in the game's save/load system.