Game.Vehicles.GuestVehicle
Assembly:
Assembly-CSharp (main game assembly for most game types)
Namespace:
Game.Vehicles
Type:
public struct GuestVehicle
Base:
System.ValueType (struct); implements Unity.Entities.IBufferElementData, System.IEquatable
Summary:
Represents a single buffer element that stores a reference to a vehicle Entity in the ECS. This struct is intended to be used inside a DynamicBuffer
Fields
public Unity.Entities.Entity m_Vehicle
Holds the Entity reference for the guest vehicle. This is the primary data carried by the buffer element and is used for equality/comparisons and identifying the vehicle within ECS.
Properties
- This type defines no properties.
Constructors
public GuestVehicle(Unity.Entities.Entity vehicle)
Initializes a new GuestVehicle with the given Entity and stores it in m_Vehicle.
Methods
-
public bool Equals(GuestVehicle other)
Implements IEquatable. Compares this.m_Vehicle to other.m_Vehicle using Entity.Equals. -
public override int GetHashCode()
Returns the hash code of the underlying Entity (m_Vehicle.GetHashCode()).
Notes:
- There is no override of Equals(object), only the IEquatable
Usage Example
using Unity.Entities;
using Game.Vehicles;
// Example: add a GuestVehicle buffer element to an entity (EntityManager usage)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity ownerEntity = /* some entity that should hold guest vehicles */;
Entity vehicleEntity = /* an Entity representing the guest vehicle */;
// Ensure the owner entity has the buffer and add an element
var buffer = em.GetBuffer<GuestVehicle>(ownerEntity); // or AddBuffer<GuestVehicle>(ownerEntity) if not present
buffer.Add(new GuestVehicle(vehicleEntity));
// Example inside a SystemBase
public partial class GuestVehicleSystem : SystemBase
{
protected override void OnUpdate()
{
Entity someVehicle = /* obtain or compute vehicle entity */;
Entities
.WithNone<SomeMarkerComponent>() // example filter
.ForEach((Entity e, int entityInQueryIndex) =>
{
var buf = EntityManager.GetBuffer<GuestVehicle>(e);
buf.Add(new GuestVehicle(someVehicle));
}).Schedule();
}
}