Game.Vehicles.PublicTransport
Assembly:
Namespace: Game.Vehicles
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
A data-only ECS component that represents public-transport-related state for a vehicle. It stores a reference to a service/request entity, a set of flags describing the transport state, timing information used for departure/path element timing, counters for outstanding requests, and configurable distances used for boarding/waiting logic. Serialization and deserialization are implemented with version checks to remain backwards-compatible across saved-game versions.
Fields
-
public Unity.Entities.Entity m_TargetRequest
Reference to an Entity that represents the active or last service/request associated with this public transport vehicle (for example a service request entity for passenger pickup). This field is only read from serialized data when the saved-game version supports reverse service requests (Version.reverseServiceRequests). -
public Game.Vehicles.PublicTransportFlags m_State
Flags (enum) describing the current state of the public transport vehicle (stored as a uint during serialization). Values encode things such as whether the vehicle is active, waiting, in transit, etc. -
public uint m_DepartureFrame
Frame index (unsigned) used to track or schedule departures. Always serialized/deserialized in supported versions. -
public int m_RequestCount
Count of outstanding or pending requests related to this vehicle. This field is deserialized only when the saved-game version is at or beyond Version.evacuationTransport. -
public float m_PathElementTime
Timing (seconds or frame-based time unit used by game) for the current/next path element. This is deserialized only when the saved-game version is at or beyond Version.evacuationTransport. -
public float m_MaxBoardingDistance
Maximum allowed distance for boarding checks. This field is deserialized only when the saved-game version is at or beyond Version.roadPatchImprovements. -
public float m_MinWaitingDistance
Minimum waiting distance used by the boarding/waiting logic. This field is deserialized only when the saved-game version is at or beyond Version.roadPatchImprovements.
Properties
- None (this type exposes only public fields).
Constructors
public PublicTransport()
The default value-type constructor is used. All numeric fields default to zero and reference fields default to Entity.Null unless initialized explicitly.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component fields to the provided writer in a fixed order:- Writes m_TargetRequest (Entity).
- Writes m_State cast to a uint.
- Writes m_DepartureFrame (uint).
- Writes m_RequestCount (int).
- Writes m_PathElementTime (float).
- Writes m_MaxBoardingDistance (float).
-
Writes m_MinWaitingDistance (float). Note: Serialize writes all fields, but deserialization is version-gated (see Deserialize).
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes component data from reader while respecting the saved-game version to maintain compatibility: - If reader.context.version >= Version.reverseServiceRequests: reads m_TargetRequest.
- Reads a uint into a temporary variable (the serialized m_State value).
- Reads m_DepartureFrame.
- If reader.context.version >= Version.evacuationTransport: reads m_RequestCount and m_PathElementTime.
- If reader.context.version >= Version.roadPatchImprovements: reads m_MaxBoardingDistance and m_MinWaitingDistance.
- Finally assigns m_State by casting the previously read uint to PublicTransportFlags. This approach ensures older saves that don't include newer fields can still be loaded.
Usage Example
using Unity.Entities;
using Game.Vehicles;
// Create and initialize a PublicTransport component and attach it to an entity:
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity vehicleEntity = entityManager.CreateEntity(typeof(PublicTransport));
var pt = new PublicTransport
{
m_TargetRequest = Entity.Null,
m_State = 0, // or (PublicTransportFlags)SomeFlag
m_DepartureFrame = (uint)UnityEngine.Time.frameCount,
m_RequestCount = 0,
m_PathElementTime = 0f,
m_MaxBoardingDistance = 5f,
m_MinWaitingDistance = 1f
};
entityManager.SetComponentData(vehicleEntity, pt);
// Example: reading and updating component inside a System
var transport = entityManager.GetComponentData<PublicTransport>(vehicleEntity);
transport.m_RequestCount++;
entityManager.SetComponentData(vehicleEntity, transport);