Game.Prefabs.CarTrailerData
Assembly: Game
Namespace: Game.Prefabs
Type: struct (value type)
Base: Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents trailer-related data attached to a vehicle. Holds the trailer's type, how it moves, the local attach position, and an optional fixed tractor entity. Note: the custom serialization implemented here only persists the movement type and the attach position — the trailer type and fixed tractor entity are not written/read by this serialization implementation.
Fields
-
public CarTrailerType m_TrailerType
Holds the trailer's logical subtype (enum CarTrailerType). Not written by the Serialize method in this implementation. -
public TrailerMovementType m_MovementType
Indicates how the trailer moves relative to its tractor (enum TrailerMovementType). This is serialized as a single byte in Serialize and restored in Deserialize. -
public float3 m_AttachPosition
Local attach position (Unity.Mathematics.float3) where the trailer connects to the tractor. This is serialized/deserialized. -
public Entity m_FixedTractor
A Unity.Entities.Entity reference to a fixed tractor (if any). This field is not serialized by the provided Serialize method and will not be restored by Deserialize.
Properties
- None (no properties are declared on this struct)
Constructors
public CarTrailerData()
(implicit default)
Struct uses the default parameterless constructor. Fields default to their type defaults (enums to 0, float3 to (0,0,0), Entity to default/Entity.Null). No custom constructors are defined.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the trailer movement and attach position to the provided writer. Implementation details:- Casts m_MovementType to byte and writes it.
- Writes m_AttachPosition (float3).
-
Does NOT write m_TrailerType or m_FixedTractor.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data in the same order written by Serialize and restores fields: - Reads a byte into a local variable and later casts it to TrailerMovementType to set m_MovementType.
- Reads into m_AttachPosition by reference.
- Leaves m_TrailerType and m_FixedTractor unchanged (they must be set elsewhere if needed).
Notes on serialization order and compatibility: - Serialize writes movement type (1 byte) first, then attach position. Deserialize expects the same order. - Because not all fields are serialized, code that relies on m_TrailerType or m_FixedTractor after deserialization must ensure those are set by other logic (defaults, separate data streams, or entity linking code).
Usage Example
// Create and populate
CarTrailerData trailer = new CarTrailerData();
trailer.m_TrailerType = CarTrailerType.Small; // example enum value
trailer.m_MovementType = TrailerMovementType.Follow; // example enum value
trailer.m_AttachPosition = new float3(0f, -0.5f, -2f);
trailer.m_FixedTractor = Entity.Null; // or a valid Entity
// Serialize (pseudo-code; actual writer implementation provided by game)
using (var writer = CreateSomeIWriter())
{
trailer.Serialize(writer);
// writer.Flush/Store as needed
}
// Deserialize (pseudo-code)
CarTrailerData loaded = new CarTrailerData();
using (var reader = CreateSomeIReaderFromStoredData())
{
loaded.Deserialize(reader);
// After this, loaded.m_MovementType and loaded.m_AttachPosition are restored.
// loaded.m_TrailerType and loaded.m_FixedTractor remain at defaults and must be handled separately.
}