Game.Prefabs.PoliceCarData
Assembly:
Assembly-CSharp
Namespace:
Game.Prefabs
Type:
struct
Base:
IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the data for a police car prefab used by the ECS (Unity.Entities) systems in Cities: Skylines 2. This value-type component stores capacity, effectiveness and shift information and supports custom binary serialization via Colossal.Serialization.Entities. Because it implements IComponentData and IQueryTypeParameter it can be attached to entities and used in queries; ISerializable provides explicit Serialize/Deserialize methods used by the game's save/load and prefab systems.
Fields
-
public int m_CriminalCapacity
Holds how many criminals (or criminal "units") a police car can handle/transport. Used by gameplay systems to determine capacity for arrests or transport. -
public float m_CrimeReductionRate
A rate (per tick/second/logic unit depending on systems) representing how effective the vehicle is at reducing crime in its operational area. Higher values reduce crime faster. -
public uint m_ShiftDuration
Length of the vehicle's shift in game-time units (uint). Represents how long the vehicle is considered active before being rotated out or returned. -
public PolicePurpose m_PurposeMask
A bitmask enum describing the roles/purposes this police car can perform (for example: patrol, emergency response, transport). Stored as a PolicePurpose value but serialized/deserialized as its underlying uint representation.
Properties
- This type exposes no C# auto-properties. It is a plain struct with public fields and explicit Serialize/Deserialize implementations.
Constructors
public PoliceCarData(int criminalCapacity, float crimeReductionRate, uint shiftDuration, PolicePurpose purposeMask)
Initializes a new PoliceCarData instance with the provided capacity, crime reduction rate, shift length, and purpose mask. Use this when creating instances in code before attaching to an entity or serializing.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the struct fields in the following order:- m_PurposeMask (written as a uint)
- m_CriminalCapacity (int)
- m_CrimeReductionRate (float)
-
m_ShiftDuration (uint)
This deterministic ordering must be matched by the Deserialize implementation used on load. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes the struct fields in the same order written by Serialize. Reads a uint for purpose mask first, then reads into the remaining fields (criminal capacity, crime reduction rate, shift duration) and finally casts the uint into PolicePurpose for m_PurposeMask. Note that the code reads the numeric fields by reference into the struct's fields.
Usage Example
// Create a PoliceCarData instance
var policeData = new PoliceCarData(
criminalCapacity: 4,
crimeReductionRate: 0.25f,
shiftDuration: 3600u,
purposeMask: PolicePurpose.Patrol // example enum value; use actual game enum flags
);
// Attach to an entity using the EntityManager (example)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity policeEntity = em.CreateEntity(typeof(PoliceCarData));
em.SetComponentData(policeEntity, policeData);
// Serialization example (pseudo-code, actual writer provided by game's serialization system)
using (var writer = GetSomeIWriter())
{
policeData.Serialize(writer);
}
// Deserialization example (pseudo-code)
using (var reader = GetSomeIReader())
{
var loaded = new PoliceCarData();
loaded.Deserialize(reader);
// now 'loaded' contains the restored values
}
Notes: - The struct uses m_ prefix naming consistent with game code conventions. - Because PolicePurpose is treated as a bitmask, multiple purposes can typically be combined with bitwise operators — consult the game's PolicePurpose enum for valid flags. - Maintain the same Serialize/Deserialize ordering when writing custom serializers or modifying the struct to ensure save/load compatibility.