Game.Vehicles.Odometer
Assembly: Assembly-CSharp
Namespace: Game.Vehicles
Type: public struct
Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Component that stores the traveled distance for a vehicle. This struct is an ECS component (IComponentData) used by the game's entity systems to track how far a vehicle has traveled. It implements ISerializable so its m_Distance value is written to/read from the game's save/load serializer.
Fields
public System.Single m_Distance
Stores the accumulated distance for the vehicle as a float (game units). This field is serialized and deserialized by the implemented ISerializable methods.
Properties
- This type has no properties.
Constructors
public Odometer()
Default value-type constructor generated by the runtime. m_Distance is initialized to 0.0f.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Distance value to the provided writer. Used by the game's serialization pipeline to save the component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the m_Distance value from the provided reader. Restores the component state during loading.
Usage Example
// Create an entity with the Odometer component and set initial distance
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(Game.Vehicles.Odometer));
var entity = entityManager.CreateEntity(archetype);
// Set the odometer distance to 0
entityManager.SetComponentData(entity, new Game.Vehicles.Odometer { m_Distance = 0f });
// Access and update distance in a system
var odometer = entityManager.GetComponentData<Game.Vehicles.Odometer>(entity);
odometer.m_Distance += travelDelta;
entityManager.SetComponentData(entity, odometer);
// Serialization usage (called by the game's save system)
// writer/reader are provided by the game's serialization framework
odometer.Serialize(writer);
// ...
odometer.Deserialize(reader);