Skip to content

Game.Prefabs.CarData

Assembly: Game
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
CarData is a value-type component that holds per‑prefab runtime and serialization data for car vehicles in the game's ECS. It stores vehicle classification (size and energy type) and basic physical/performance parameters such as max speed, acceleration, braking, pivot offset and turning characteristics. The struct implements the game's serialization interfaces to write/read a compact binary representation (enums are serialized as bytes, floats are written directly) and is intended to be used as an ECS component (Unity.Entities.IComponentData) or as a parameter type for queries.


Fields

  • public SizeClass m_SizeClass
    Represents the size classification of the car prefab (an enum). Serialized as a single byte.

  • public EnergyTypes m_EnergyType
    Represents the energy/fuel type of the car prefab (an enum). Serialized as a single byte.

  • public float m_MaxSpeed
    Maximum speed of the vehicle. Serialized as a 32-bit float.

  • public float m_Acceleration
    Acceleration value used by vehicle movement logic. Serialized as a 32-bit float.

  • public float m_Braking
    Braking (deceleration) value used by vehicle movement logic. Serialized as a 32-bit float.

  • public float m_PivotOffset
    Pivot offset for the vehicle's geometry/turning pivot. Serialized as a 32-bit float.

  • public float2 m_Turning
    Two-component turning parameter (Unity.Mathematics.float2) — likely represents turning radii/limits or steering parameters. Serialized as a float2 (two 32-bit floats).

Properties

  • None (this struct exposes its data via public fields and does not define properties).

Constructors

  • public CarData()
    No explicit constructors are declared in the source. The struct uses the default parameterless constructor provided by C#. When added to entities, values should be initialized explicitly before use.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to a writer in the following order:
  • m_SizeClass cast to byte
  • m_EnergyType cast to byte
  • m_MaxSpeed (float)
  • m_Acceleration (float)
  • m_Braking (float)
  • m_PivotOffset (float)
  • m_Turning (float2)

Notes: - Enums are explicitly serialized as single bytes — the reader must read them as bytes and cast back to the enum. - Order and types must match Deserialize exactly for compatibility.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data from a reader in the order expected by Serialize:
  • Reads a byte for size class (stored temporarily, assigned to m_SizeClass at the end).
  • Reads a byte for energy type (stored temporarily, assigned to m_EnergyType at the end).
  • Reads m_MaxSpeed (float)
  • Reads m_Acceleration (float)
  • Reads m_Braking (float)
  • Reads m_PivotOffset (float)
  • Reads m_Turning (float2)

Implementation notes: - The method reads numeric fields by reference into the struct fields directly (via ref locals). - After reading numeric values, it assigns the enum fields by casting the previously read bytes back to the enum types.

Usage Example

// Example: creating and serializing a CarData instance
CarData car = new CarData();
car.m_SizeClass = SizeClass.Medium;
car.m_EnergyType = EnergyTypes.Petrol;
car.m_MaxSpeed = 28.0f;
car.m_Acceleration = 3.5f;
car.m_Braking = 4.2f;
car.m_PivotOffset = 0.1f;
car.m_Turning = new float2(0.6f, 0.8f);

// Serialize using an IWriter implementation
someWriter.WriteEntityStart();
car.Serialize(someWriter);
someWriter.WriteEntityEnd();

// Deserialize from an IReader implementation
CarData loaded = new CarData();
loaded.Deserialize(someReader);

Additional notes and caveats: - Serialization format is compact and order-dependent. Modifying the order or types requires versioning support in reader/writer logic to remain compatible with existing saved data. - Because this is an ECS component (IComponentData), instances are typically stored on entities; use Unity.Entities APIs to add/remove/query this component. - float2 is from Unity.Mathematics — ensure your code importing or using this struct has the appropriate using directive and that the serialization system supports float2.