Game.Prefabs.TransportStopData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType (implements IComponentData, IQueryTypeParameter, ISerializable)
Summary:
TransportStopData is a value-type ECS component that holds configuration data for a transport stop (comfort, loading/access/boarding parameters and transport capabilities). It implements IComponentData for use with Unity Entities, IQueryTypeParameter (to allow use in certain query APIs), and a custom ISerializable implementation to persist a subset of its fields (transport type and transport flags).
Fields
-
public float m_ComfortFactor
Comfort multiplier or score applied to passengers using this stop. Used by simulation systems to influence passenger satisfaction and behavior. Not serialized by the custom Serialize method. -
public float m_LoadingFactor
Influences loading/unloading efficiency or throughput at the stop. Not serialized by the custom Serialize method. -
public float m_AccessDistance
Maximum distance (in game units) passengers consider the stop accessible. Not serialized by the custom Serialize method. -
public float m_BoardingTime
Time taken for boarding at this stop. Not serialized by the custom Serialize method. -
public TransportType m_TransportType
Enum indicating the transport mode served by this stop (e.g., Bus, Metro, Train). This field is serialized as an sbyte in Serialize and restored in Deserialize. -
public bool m_PassengerTransport
Whether the stop serves passenger transport. Serialized by Serialize and read by Deserialize. -
public bool m_CargoTransport
Whether the stop serves cargo transport. Serialized by Serialize and read by Deserialize.
Properties
- (none)
This struct exposes fields directly; there are no C# properties defined in the source.
Constructors
public TransportStopData()
No explicit constructors are defined in the source file; the default parameterless value-type constructor is used. Instantiate with the default or with an object initializer to set fields.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes a compact representation of the component to the provided writer. Implementation details:- Casts
m_TransportType
tosbyte
and callswriter.Write(sbyte)
. - Writes
m_PassengerTransport
andm_CargoTransport
as booleans. -
Note: The float fields (comfort/loading/access/boarding) are not written by this method.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data in the same order as Serialize: - Reads an
sbyte
and stores it temporarily, later cast back toTransportType
intom_TransportType
. - Reads booleans into
m_PassengerTransport
andm_CargoTransport
. - Leaves the float fields unchanged (they must be set elsewhere or have defaults).
Important notes about serialization: - The serialization intentionally writes only the transport type and the two booleans. Any systems relying on persisted floats will need to handle those separately. - The methods are generic over writer/reader implementations that conform to IWriter/IReader.
Usage Example
// Create and populate the component, then add it to an entity (EntityManager world code)
var stopData = new TransportStopData {
m_ComfortFactor = 1.1f,
m_LoadingFactor = 0.9f,
m_AccessDistance = 12f,
m_BoardingTime = 2.5f,
m_TransportType = TransportType.Bus,
m_PassengerTransport = true,
m_CargoTransport = false
};
var entityManager = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(TransportStopData));
var entity = entityManager.CreateEntity(archetype);
entityManager.SetComponentData(entity, stopData);
// Example: serializing only the transport type and flags (writer must implement IWriter)
stopData.Serialize(myWriter);
// Example: deserializing (reader must implement IReader)
TransportStopData loaded = new TransportStopData();
loaded.Deserialize(myReader);
// Note: loaded.m_ComfortFactor etc. will still need initialization if required.