Game.Prefabs.CarTractorData
Assembly: Assembly-CSharp (game)
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
CarTractorData is an ECS component used to store configuration/state for a tractor car that can tow a trailer. It holds the trailer type, the attachment offset (position) and an optional fixed trailer Entity reference. The component implements ISerializable to custom-serialize its attachment position for save/load and persistence systems.
Fields
-
public CarTrailerType m_TrailerType
Represents the type of trailer attached to the tractor (likely an enum defined elsewhere). This field is used by game logic to pick trailer behavior/visuals. Note: this field is not serialized by the provided Serialize method. -
public float3 m_AttachPosition
Local attachment offset where the trailer connects to the tractor. This is the only field that the component's ISerializable implementation writes/reads (Serialize/Deserialize). Uses Unity.Mathematics.float3. -
public Entity m_FixedTrailer
If a trailer is a fixed entity instance, this stores the Entity reference to that trailer. This is not serialized by the provided Serialize method.
Properties
- None. (This type exposes public fields and does not define C# properties.)
Constructors
public CarTractorData()
Implicit parameterless default constructor generated for the struct. Default values:- m_TrailerType: default enum value (0)
- m_AttachPosition: float3(0,0,0)
- m_FixedTrailer: Entity.Null
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component's attach position to the supplied writer. Implementation: writer.Write(m_AttachPosition); Used by the game's custom serialization system to persist position data. Only m_AttachPosition is serialized. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the attach position from the supplied reader into m_AttachPosition. Implementation: reader.Read(out m_AttachPosition); Other fields (m_TrailerType, m_FixedTrailer) are not restored by this method and should be set/validated separately if needed.
Usage Example
// Create and add the component to an entity (ECS usage)
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity tractorEntity = em.CreateEntity();
var tractor = new CarTractorData {
m_TrailerType = CarTrailerType.SmallTrailer,
m_AttachPosition = new float3(0f, -1.2f, 0f),
m_FixedTrailer = Entity.Null
};
em.AddComponentData(tractorEntity, tractor);
// Serialization usage (example - actual writer comes from Colossal.Serialization system)
tractor.Serialize(someWriter); // writes m_AttachPosition via writer.Write(...)
Notes: - Because only m_AttachPosition is serialized, ensure any required trailer type or entity references are restored by game logic or custom save handlers. - This component is intended for use with Unity.Entities (DOTS/ECS) in Cities: Skylines 2 modding context.