Game.Vehicles.Passenger
Assembly:
Assembly-CSharp (Unity game assembly)
Namespace:
Game.Vehicles
Type:
struct
Base:
Implements Unity.Entities.IBufferElementData, System.IEquatable
Summary:
Represents a passenger entry stored in an ECS dynamic buffer for vehicles. The struct wraps a single Unity.Entities.Entity reference (the passenger entity) and provides equality and hashing implementations. The struct is annotated with [InternalBufferCapacity(0)], indicating no preallocated inline capacity for the buffer (purely dynamic).
Fields
-
public Unity.Entities.Entity m_Passenger
Holds the Entity reference that represents the passenger. This is the value stored for each buffer element. -
Attribute:
[InternalBufferCapacity(0)]
Specifies the internal buffer capacity for the dynamic buffer type. A value of 0 means the buffer has no small-object inline capacity and will allocate dynamically as needed.
Properties
- (none)
This struct exposes its data via the public field m_Passenger; there are no C# properties defined.
Constructors
public Passenger(Unity.Entities.Entity passenger)
Initializes a new Passenger buffer element with the provided passenger entity.
Usage: Construct this when adding a passenger entry to a DynamicBuffer
Methods
-
public bool Equals(Passenger other)
Implements IEquatable. Compares this instance to another Passenger by comparing their m_Passenger Entity values. -
public override int GetHashCode()
Returns the hash code of the contained Entity (m_Passenger). Useful when Passenger instances are used in hashed collections or comparisons.
Remarks / Notes
- Implements IBufferElementData so instances are intended to be stored in Unity's DynamicBuffer
attached to entities (for example, a vehicle entity's passenger list). - Implements IEmptySerializable (from Colossal.Serialization.Entities) to participate correctly in the game's custom serialization system.
- Equality is based solely on the Entity field; two Passenger instances referencing the same Entity are considered equal.
Usage Example
using Unity.Entities;
using Game.Vehicles;
// Add a passenger entity to a vehicle's passenger buffer
public void AddPassengerToVehicle(EntityManager entityManager, Entity vehicleEntity, Entity passengerEntity)
{
// Ensure the vehicle has the buffer (AddBuffer will create it if missing)
var buffer = entityManager.GetBuffer<Passenger>(vehicleEntity);
buffer.Add(new Passenger(passengerEntity));
}
// Check if a vehicle already has a given passenger
public bool VehicleHasPassenger(EntityManager entityManager, Entity vehicleEntity, Entity passengerEntity)
{
if (!entityManager.HasComponent<Passenger>(vehicleEntity))
return false;
var buffer = entityManager.GetBuffer<Passenger>(vehicleEntity);
foreach (var p in buffer)
{
if (p.Equals(new Passenger(passengerEntity)))
return true;
}
return false;
}