Game.Routes.VehicleModel
Assembly:
Game
Namespace:
Game.Routes
Type:
struct
Base:
IComponentData, IQueryTypeParameter, ISerializable
Summary:
VehicleModel is a lightweight ECS component (value type) that holds references to two vehicle prefab Entities used by routing/spawning systems. It implements Colossal.Serialization.Entities.ISerializable so the two Entity references are written/read during save/load. As an IComponentData it can be attached to Entities and queried by Unity's ECS; implementing IQueryTypeParameter allows it to be used directly in query type parameter lists.
Fields
-
public Unity.Entities.Entity m_PrimaryPrefab
Holds the primary vehicle prefab Entity reference. This is typically an Entity representing the main prefab used for spawning the vehicle. When serialized, this field is written first. If no prefab is assigned it will typically be Entity.Null. -
public Unity.Entities.Entity m_SecondaryPrefab
Holds the secondary vehicle prefab Entity reference (for example alternate visual or variant). This is written/read second during serialization. Also may be Entity.Null when not used.
Properties
- This type does not declare any managed properties. It exposes two public fields for data storage.
Constructors
public VehicleModel()
Default parameterless struct constructor (implicitly defined). Use object initializer syntax to set fields when creating an instance.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component's data to a writer for persistence. The implementation writes m_PrimaryPrefab then m_SecondaryPrefab using writer.Write(Entity). The ordering must match Deserialize. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component's data from a reader. The implementation reads into m_PrimaryPrefab and m_SecondaryPrefab (by ref) using reader.Read(out Entity). The expected read order is primary then secondary to match Serialize.
Usage Example
// Create and attach the component to an Entity (EntityManager in scope)
var vehicleModel = new Game.Routes.VehicleModel {
m_PrimaryPrefab = primaryVehicleEntity,
m_SecondaryPrefab = secondaryVehicleEntity
};
entityManager.AddComponentData(targetEntity, vehicleModel);
// The serialization methods are invoked by the game's serialization system (ISerializable).
// Manual serialization is normally not needed; shown here for clarity of construction.